Skip to content

Commit 73e7a58

Browse files
author
Workflow Sync Bot
committed
💬 - Files Synced | Runner ID : 17 | ⚡ Triggered By run-ai/devops
1 parent 1370442 commit 73e7a58

5 files changed

Lines changed: 597 additions & 0 deletions

File tree

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
2+
import requests
3+
from requests.auth import HTTPBasicAuth
4+
import json
5+
import os
6+
7+
#### CUSTOM JIRA FIELDS
8+
# master repos: customfield_10080
9+
10+
11+
WORKFLOW_DEBUG=False
12+
13+
# ENV VARs
14+
if WORKFLOW_DEBUG == True:
15+
print ('debug')
16+
JIRA_USER=os.environ['JIRA_USER'] # must be in .zshrc
17+
JIRA_API_TOKEN=os.environ['JIRA_API_TOKEN'] # must be in .zshrc
18+
GITHUB_REPOSITORY="run-ai/backend"
19+
else:
20+
JIRA_USER="jira-bot@run.ai"
21+
JIRA_API_TOKEN = os.environ['JIRA_API_TOKEN']
22+
GITHUB_REPOSITORY = os.environ['GITHUB_REPOSITORY']
23+
24+
25+
# CONSTANTS
26+
base_jira_url = "https://runai.atlassian.net/rest/api/3"
27+
28+
29+
30+
auth = HTTPBasicAuth(JIRA_USER, JIRA_API_TOKEN)
31+
32+
headers = {
33+
"Accept": "application/json",
34+
"Content-Type": "application/json"
35+
}
36+
37+
38+
39+
#JIRA API CALLS
40+
41+
42+
def jira_get_jql(fields, jql):
43+
query = {
44+
'fields' : fields,
45+
'jql': jql
46+
}
47+
response = requests.request("GET", base_jira_url + "/search", params=query, headers=headers, auth=auth)
48+
if response.status_code //100 != 2:
49+
print (response.text)
50+
else:
51+
js = json.loads(response.text)
52+
print(json.dumps(js, sort_keys=True, indent=4, separators=(",", ": ")))
53+
return js["issues"]
54+
55+
56+
57+
def jira_set_comment (key, comment):
58+
payload = {
59+
"body": {
60+
"type": "doc",
61+
"version": 1,
62+
"content": [
63+
{
64+
"type": "paragraph",
65+
"content": [
66+
{
67+
"text": comment,
68+
"type": "text"
69+
}
70+
]
71+
}
72+
]
73+
}
74+
}
75+
response = requests.request("POST", base_jira_url + "/issue/" + key + "/comment", json=payload, headers=headers, auth=auth)
76+
if response.status_code //100 != 2:
77+
print (response.text)
78+
# print(json.dumps(json.loads(response.text), sort_keys=True, indent=4, separators=(",", ": ")))
79+
80+
return
81+
82+
83+
84+
def jira_update_fields(key, fields):
85+
payload = { "update" : fields }
86+
response = requests.request("PUT", base_jira_url + "/issue/" + key, json=payload, headers=headers, auth=auth)
87+
if response.status_code //100 != 2:
88+
print (response.text)
89+
return response
90+
91+
92+
93+
94+
95+
def main():
96+
print(GITHUB_REPOSITORY)
97+
98+
issues = jira_get_jql("key", '"Develop repos[Labels]" in ("' + GITHUB_REPOSITORY + '") and ( "Master repos[Labels]" is EMPTY or "Master repos[Labels]" not in ("' + GITHUB_REPOSITORY + '"))')
99+
for issue in issues:
100+
print(issue["key"])
101+
102+
# - set "Master version"
103+
# - add new repo to Production repos and Tagged repos
104+
fields = {
105+
# "customfield_10074" : [{"set" : "Production" }],
106+
"customfield_10080" : [{"add" : GITHUB_REPOSITORY }]
107+
}
108+
jira_update_fields(issue["key"], fields)
109+
110+
# Add a merge master comment to Jira
111+
jira_set_comment(issue["key"], "merged to master using repository: " + GITHUB_REPOSITORY)
112+
113+
114+
115+
116+
117+
118+
if __name__ == "__main__":
119+
main()

0 commit comments

Comments
 (0)