-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
86 lines (78 loc) · 2.5 KB
/
index.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
76
77
78
79
80
81
82
83
84
85
86
var request = require("request-promise-native");
function getWorkspaceOidFromUUID(apiKey, workspaceUUID) {
var options = {
"method": "GET",
"url": 'https://rally1.rallydev.com/slm/webservice/v2.0/workspace',
"qs": {
query: `(ObjectUUID = "${workspaceUUID}")`,
fetch: "ObjectID"
},
"headers": {
"content-type": "application/json",
"cookie": `ZSESSIONID=${apiKey}`
},
"json": true
};
return request(options).then(body => {
return body.QueryResult.Results[0].ObjectID;
});
}
function getTypeDefinition(apiKey, workspaceOid, type) {
var options = {
"method": "GET",
"url": 'https://rally1.rallydev.com/slm/webservice/v2.0/typedefinition',
"qs": {
query: '(ElementName = "' + type + '")',
workspace: 'https://rally1.rallydev.com/slm/webservice/v2.0/workspace/' + workspaceOid
},
"headers": {
"content-type": "application/json",
"cookie": `ZSESSIONID=${apiKey}`
},
"json": true
};
return request(options).then(body => {
return body.QueryResult.Results[0]._ref;
});
}
function getElementNameUUIDFromTypeDef(apiKey, typeDef, name) {
var options = {
"method": "GET",
"url": typeDef + '/Attributes',
"qs": {
query: '(Name = "' + name + '")',
fetch: "ObjectUUID"
},
"headers": {
"content-type": "application/json",
"cookie": `ZSESSIONID=${apiKey}`
},
"json": true
};
return request(options).then(body => {
return body.QueryResult.Results[0].ObjectUUID;
});
}
function attributeNameToUUID(apiKey, workspaceUUID, typeName, attributeName) {
return getWorkspaceOidFromUUID(apiKey, workspaceUUID)
.then(workspaceOid => {
return getTypeDefinition(apiKey, workspaceOid, typeName)
})
.then((typeDef) => {
return getElementNameUUIDFromTypeDef(apiKey, typeDef, attributeName);
});
}
module.exports.attributeNameToUUID = attributeNameToUUID;
/*
//manual test code
attributeNameToUUID(
process.env.WEBHOOK_RALLY_WORKSPACE_UUID,
"PortfolioItem",
"Send Epic to SNOW Indicator (DSE ONLY)")
.then(uuid => console.log(uuid));
attributeNameToUUID(
process.env.WEBHOOK_RALLY_WORKSPACE_UUID,
"PortfolioItem",
"SNOW Status (Don't Touch Admin ONLY)")
.then(uuid => console.log(uuid));
*/