This repository has been archived by the owner on Aug 16, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
createIssue.js
79 lines (60 loc) · 2.01 KB
/
createIssue.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Licensed to the Apache Software Foundation (ASF) under one or more contributor
// license agreements; and to You under the Apache License, Version 2.0.
/***********************************************************
Create Issue in Jira. Issue is encoded as a JSON object
in the form:
{
"fields": {
"project":
{
"key": "TEST"
},
"summary": "REST ye merry gentlemen.",
"description": "Creating of an issue using project keys and issue type names using the REST API",
"issuetype": {
"name": "Bug"
}
}
}
For project, key is the key value assigned to a Jira project, e.g. "MyAwesomeScrumProject"
may have the key "MYAW"
@param issue the jsonObject representing the issue
@return response from Jira representing succes or failure
***********************************************************/
var request = require('request');
function main(params) {
if (!(params.jiraUsername && params.jiraPassword)) {
return whisk.error("Jira credentials not set")
}
if (!params.jiraHost) {
return whisk.error("Location of Jira server not set")
}
if (!params.issue) {
return whisk.error("No issue data to create")
}
var issue = params.issue
var username = params.jiraUsername
var password = params.jiraPassword
var url = 'https://' + username+":" + password + '@'+params.jiraHost+"/rest/api/2/issue/"
console.log("Got url " + url)
var options = {
headers: {
'Content-Type': 'application/json'
},
method: "POST",
json: issue
}
console.log("Making call with options "+ JSON.stringify(options))
request(url, options, function (error, response, body) {
console.log("In callback")
if (!error && response.statusCode > 200 && response.statusCode < 300 ) {
//var info = JSON.parse(body);
console.log("Got body "+body)
return whisk.done(body)
} else {
return whisk.error("Got error "+ error + " status code "+response.statusCode)
}
});
console.log("Async")
return whisk.async()
}