Skip to content

Commit 5bf1c43

Browse files
committed
Format SCMManager like other files and add .editorconfig
1 parent 3fa0992 commit 5bf1c43

File tree

3 files changed

+207
-197
lines changed

3 files changed

+207
-197
lines changed

.editorconfig

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# top-most EditorConfig file
2+
root = true
3+
4+
[*]
5+
indent_style = space
6+
# Unix-style newlines with a newline ending every file
7+
end_of_line = lf
8+
charset = utf-8
9+
insert_final_newline = true
10+
indent_size = 4

src/com/cloudogu/ces/cesbuildlib/SCMManager.groovy

+99-99
Original file line numberDiff line numberDiff line change
@@ -2,115 +2,115 @@ package com.cloudogu.ces.cesbuildlib
22

33
import groovy.json.JsonOutput
44

5-
class SCMManager implements Serializable{
6-
7-
private script
8-
private HttpClient http
9-
String repositoryUrl
10-
11-
SCMManager(script, credentials) {
12-
this.script = script
13-
this.http = new HttpClient(script, credentials)
14-
}
15-
16-
String searchPullRequestIdByTitle(String title) {
17-
def pullRequest
18-
for (Map pr : getPullRequests()) {
19-
if (pr.title == title) {
20-
pullRequest = pr
21-
}
22-
}
23-
24-
if (pullRequest) {
25-
return pullRequest.id.toString()
26-
} else {
27-
return ""
5+
class SCMManager implements Serializable {
6+
7+
private script
8+
private HttpClient http
9+
String repositoryUrl
10+
11+
SCMManager(script, credentials) {
12+
this.script = script
13+
this.http = new HttpClient(script, credentials)
2814
}
29-
}
30-
31-
String createPullRequest(String source, String target, String title, String description) {
32-
def dataJson = JsonOutput.toJson([
33-
title: title,
34-
description: description,
35-
source: source,
36-
target: target
37-
])
38-
def httpResponse = http.post("https://${this.repositoryUrl}", 'application/vnd.scmm-pullRequest+json;v=2', dataJson)
39-
40-
script.echo "Creating pull request yields httpCode: ${httpResponse.httpCode}"
41-
if (httpResponse.httpCode != "201") {
42-
script.echo 'WARNING: Http status code indicates, that pull request was not created'
43-
script.unstable 'Could not create pull request'
44-
return ''
15+
16+
String searchPullRequestIdByTitle(String title) {
17+
def pullRequest
18+
for (Map pr : getPullRequests()) {
19+
if (pr.title == title) {
20+
pullRequest = pr
21+
}
22+
}
23+
24+
if (pullRequest) {
25+
return pullRequest.id.toString()
26+
} else {
27+
return ""
28+
}
4529
}
4630

47-
// example: "location: https://some/pr/42" - extract ide
48-
return httpResponse.headers.location.split("/")[-1]
49-
}
31+
String createPullRequest(String source, String target, String title, String description) {
32+
def dataJson = JsonOutput.toJson([
33+
title : title,
34+
description: description,
35+
source : source,
36+
target : target
37+
])
38+
def httpResponse = http.post("https://${this.repositoryUrl}", 'application/vnd.scmm-pullRequest+json;v=2', dataJson)
39+
40+
script.echo "Creating pull request yields httpCode: ${httpResponse.httpCode}"
41+
if (httpResponse.httpCode != "201") {
42+
script.echo 'WARNING: Http status code indicates, that pull request was not created'
43+
script.unstable 'Could not create pull request'
44+
return ''
45+
}
46+
47+
// example: "location: https://some/pr/42" - extract ide
48+
return httpResponse.headers.location.split("/")[-1]
49+
}
5050

51-
void updateDescription(String pullRequestId, String title, String description) {
52-
// In order to update the description put in also the title. Otherwise the title is overwritten with an empty string.
53-
def dataJson = JsonOutput.toJson([
54-
title: title,
55-
description: description
56-
])
51+
void updateDescription(String pullRequestId, String title, String description) {
52+
// In order to update the description put in also the title. Otherwise the title is overwritten with an empty string.
53+
def dataJson = JsonOutput.toJson([
54+
title : title,
55+
description: description
56+
])
5757

58-
def httpResponse = http.put("https://${this.repositoryUrl}/${pullRequestId}", 'application/vnd.scmm-pullRequest+json;v=2', dataJson)
58+
def httpResponse = http.put("https://${this.repositoryUrl}/${pullRequestId}", 'application/vnd.scmm-pullRequest+json;v=2', dataJson)
5959

60-
script.echo "Description update yields http_code: ${httpResponse.httpCode}"
61-
if (httpResponse.httpCode != "204") {
62-
script.unstable 'Could not update description'
60+
script.echo "Description update yields http_code: ${httpResponse.httpCode}"
61+
if (httpResponse.httpCode != "204") {
62+
script.unstable 'Could not update description'
63+
}
6364
}
64-
}
6565

66-
void addComment(String pullRequestId, String comment) {
67-
def dataJson = JsonOutput.toJson([
68-
comment: comment
69-
])
70-
def httpResponse = http.post("https://${this.repositoryUrl}/${pullRequestId}/comments", 'application/json', dataJson)
66+
void addComment(String pullRequestId, String comment) {
67+
def dataJson = JsonOutput.toJson([
68+
comment: comment
69+
])
70+
def httpResponse = http.post("https://${this.repositoryUrl}/${pullRequestId}/comments", 'application/json', dataJson)
7171

72-
script.echo "Adding comment yields http_code: ${httpResponse.httpCode}"
73-
if (httpResponse.httpCode != "201") {
74-
script.unstable 'Could not add comment'
75-
}
76-
}
77-
78-
/**
79-
* @return SCM-Manager's representation of PRs. Basically a list of PR objects.
80-
* properties (as of SCM-Manager 2.12.0)
81-
* * id
82-
* * author
83-
* * id
84-
* * displayName
85-
* * mail
86-
* * source - the source branch
87-
* * target - the target branch
88-
* * title
89-
* * description (branch)
90-
* * creationDate: (e.g. "2020-10-09T15:08:11.459Z")
91-
* * lastModified"
92-
* * status, e.g. "OPEN"
93-
* * reviewer (list)
94-
* * tasks
95-
* * todo (number)
96-
* * done (number
97-
* * tasks sourceRevision
98-
* * targetRevision
99-
* * targetRevision
100-
* * markedAsReviewed (list)
101-
* * emergencyMerged
102-
* * ignoredMergeObstacles
103-
*/
104-
protected getPullRequests() {
105-
def httpResponse = http.get("https://${this.repositoryUrl}", 'application/vnd.scmm-pullRequestCollection+json;v=2')
106-
107-
script.echo "Getting all pull requests yields httpCode: ${httpResponse.httpCode}"
108-
if (httpResponse.httpCode != "200") {
109-
script.unstable 'Could not create pull request'
72+
script.echo "Adding comment yields http_code: ${httpResponse.httpCode}"
73+
if (httpResponse.httpCode != "201") {
74+
script.unstable 'Could not add comment'
75+
}
11076
}
11177

112-
def prsAsJson = script.readJSON text: httpResponse.body
113-
return prsAsJson._embedded.pullRequests
114-
}
78+
/**
79+
* @return SCM-Manager's representation of PRs. Basically a list of PR objects.
80+
* properties (as of SCM-Manager 2.12.0)
81+
* * id
82+
* * author
83+
* * id
84+
* * displayName
85+
* * mail
86+
* * source - the source branch
87+
* * target - the target branch
88+
* * title
89+
* * description (branch)
90+
* * creationDate: (e.g. "2020-10-09T15:08:11.459Z")
91+
* * lastModified"
92+
* * status, e.g. "OPEN"
93+
* * reviewer (list)
94+
* * tasks
95+
* * todo (number)
96+
* * done (number
97+
* * tasks sourceRevision
98+
* * targetRevision
99+
* * targetRevision
100+
* * markedAsReviewed (list)
101+
* * emergencyMerged
102+
* * ignoredMergeObstacles
103+
*/
104+
protected getPullRequests() {
105+
def httpResponse = http.get("https://${this.repositoryUrl}", 'application/vnd.scmm-pullRequestCollection+json;v=2')
106+
107+
script.echo "Getting all pull requests yields httpCode: ${httpResponse.httpCode}"
108+
if (httpResponse.httpCode != "200") {
109+
script.unstable 'Could not create pull request'
110+
}
111+
112+
def prsAsJson = script.readJSON text: httpResponse.body
113+
return prsAsJson._embedded.pullRequests
114+
}
115115

116116
}

0 commit comments

Comments
 (0)