@@ -2,115 +2,115 @@ package com.cloudogu.ces.cesbuildlib
2
2
3
3
import groovy.json.JsonOutput
4
4
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)
28
14
}
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
+ }
45
29
}
46
30
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
+ }
50
50
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
+ ])
57
57
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)
59
59
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
+ }
63
64
}
64
- }
65
65
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)
71
71
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
+ }
110
76
}
111
77
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
+ }
115
115
116
116
}
0 commit comments