-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclose_issue.py
49 lines (42 loc) · 1.42 KB
/
close_issue.py
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
import json
import requests
import logging
class CloseOpenIssue():
def __init__(self, key):
self.url = 'https://api.newrelic.com/graphql'
self.headers = {
'Content-Type': 'application/json',
'API-Key': key
}
self.vars = {}
def sendRequest(self, q):
res = requests.request("POST", self.url, headers=self.headers, json={'query': q, 'variables': self.vars})
return res
def closeIssue(self, accountId, issueToClose):
mutation = f'''
mutation {{
aiIssuesResolveIssue(accountId: {accountId}, issueId: "{issueToClose}") {{
error
result {{
action
issueId
accountId
}}
}}
}}
'''
res = ''
try:
resp = self.sendRequest(mutation)
logging.debug('CloseIssue')
logging.debug(resp.json())
parsed = resp.json()
if (parsed['data']['aiIssuesResolveIssue']['error'] is None):
res = 'success'
else:
res = 'failed'
logging.error('Failed to close issue. Response: ' + resp['data']['aiIssuesResolveIssue']['error'])
except Exception as e:
logging.exception('Exception occurred - Failed to close issue: ' + issueToClose)
raise
return(res)