oscerd commented on code in PR #345:
URL: https://github.com/apache/airflow-steward/pull/345#discussion_r3318714486


##########
tools/jira/bridge.groovy:
##########
@@ -130,20 +202,172 @@ def cmd_projects(List args) {
     ])
 }
 
+def cmd_comment(List args) {
+    def key = args ? args[0] : null
+    validateKey(key)
+    String bodyFile = null
+    def i = 1
+    while (i < args.size()) {
+        if (args[i] == '--body-file' && i + 1 < args.size()) {
+            bodyFile = args[i + 1]
+            i += 2
+        } else {
+            i++
+        }
+    }
+    if (!bodyFile) {
+        System.err.println('error: comment requires --body-file <path>')
+        System.exit(2)
+    }
+    def f = new File(bodyFile)
+    if (!f.exists()) {
+        System.err.println("error: body file not found: ${bodyFile}")
+        System.exit(2)
+    }
+    def body = f.text
+    def url = "${TRACKER_URL}/rest/api/2/issue/${key}/comment"
+    def payload = JsonOutput.toJson([body: body])
+    def result = httpWrite(url, 'POST', payload)
+    emit([ok: true, key: key, commentId: result.id])
+}
+
+def cmd_transition(List args) {
+    def key = args ? args[0] : null
+    validateKey(key)
+    def transitionName = args.size() > 1 ? args[1] : null
+    if (!transitionName) {
+        System.err.println('error: transition requires a transition name')
+        System.exit(2)
+    }
+    def url = "${TRACKER_URL}/rest/api/2/issue/${key}/transitions"
+    def available = httpGet(url)
+    def match = available.transitions?.find {
+        it.name.equalsIgnoreCase(transitionName)
+    }
+    if (!match) {
+        def names = available.transitions?.collect { it.name } ?: []
+        System.err.println("error: transition '${transitionName}' not found 
for ${key}; available: ${names}")
+        System.exit(3)
+    }
+    def payload = JsonOutput.toJson([transition: [id: match.id]])
+    httpWrite(url, 'POST', payload)
+    emit([ok: true, key: key, transition: match.name, transitionId: match.id])
+}
+
+def cmd_label(List args) {
+    def key = args ? args[0] : null
+    validateKey(key)
+    List addLabels = []
+    List removeLabels = []
+    def i = 1
+    while (i < args.size()) {
+        if (args[i] == '--add' && i + 1 < args.size()) {
+            addLabels << args[i + 1]
+            i += 2
+        } else if (args[i] == '--remove' && i + 1 < args.size()) {
+            removeLabels << args[i + 1]
+            i += 2
+        } else {
+            i++
+        }
+    }
+    if (!addLabels && !removeLabels) {
+        System.err.println('error: label requires at least one --add or 
--remove flag')
+        System.exit(2)
+    }
+    def issueUrl = "${TRACKER_URL}/rest/api/2/issue/${key}?fields=labels"
+    def current = httpGet(issueUrl)
+    def labels = (current.fields?.labels ?: []) as List
+    labels.addAll(addLabels)
+    labels.removeAll(removeLabels)
+    labels = labels.unique()
+    def url = "${TRACKER_URL}/rest/api/2/issue/${key}"
+    def payload = JsonOutput.toJson([fields: [labels: labels]])
+    httpWrite(url, 'PUT', payload)
+    emit([ok: true, key: key, labels: labels])
+}
+
+def cmd_assign(List args) {
+    def key = args ? args[0] : null
+    validateKey(key)
+    def username = args.size() > 1 ? args[1] : null
+    if (!username) {
+        System.err.println('error: assign requires a username')
+        System.exit(2)
+    }
+    def url = "${TRACKER_URL}/rest/api/2/issue/${key}/assignee"
+    def payload = JsonOutput.toJson([name: username])
+    httpWrite(url, 'PUT', payload)
+    emit([ok: true, key: key, assignee: username])
+}
+
+def cmd_field(List args) {
+    def key = args ? args[0] : null
+    validateKey(key)
+    def fieldName = args.size() > 1 ? args[1] : null
+    if (!fieldName) {
+        System.err.println('error: field requires a field name')
+        System.exit(2)
+    }
+    String value = null
+    def i = 2
+    while (i < args.size()) {
+        if (args[i] == '--value' && i + 1 < args.size()) {
+            value = args[i + 1]
+            i += 2
+        } else {
+            i++
+        }
+    }
+    if (value == null) {
+        System.err.println('error: field requires --value <value>')
+        System.exit(2)
+    }
+    def url = "${TRACKER_URL}/rest/api/2/issue/${key}"
+    def payload = JsonOutput.toJson([fields: [(fieldName): value]])

Review Comment:
   Fixed — added `--value-json <json>` as an alternative to `--value <str>`. 
Structured values (priority objects, version arrays, select fields) go through 
`--value-json` and are parsed before being sent to JIRA. Added two test cases 
covering object and array payloads.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to