Skip to content

Commit 52bfe32

Browse files
updated code to rolloout basic labels to all repos DEVOPS-283
1 parent dd2249e commit 52bfe32

File tree

1 file changed

+80
-1
lines changed

1 file changed

+80
-1
lines changed

create_new_labels.py

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def list_repos_in_org(org_name: str):
4949
for repo in all_repositories:
5050
print(repo['name'])
5151
repo_names.append(repo['name'])
52-
52+
print(f"Found {len(repo_names)} in {org_name}")
5353
print(f'Listing Public repos in {org_name} completed')
5454
return repo_names
5555

@@ -68,6 +68,10 @@ def create_new_label(repo_names: list[str], org_name: str):
6868
color2 = random.choice(colors)
6969
color3 = random.choice(colors)
7070
color4 = random.choice(colors)
71+
color5 = random.choice(colors)
72+
color6 = random.choice(colors)
73+
color7 = random.choice(colors)
74+
color8 = random.choice(colors)
7175
for repository in repo_names:
7276
api_endpoint=f'https://api.github.com/repos/{org_name}/{repository}/labels'
7377

@@ -101,6 +105,27 @@ def create_new_label(repo_names: list[str], org_name: str):
101105
"color": color4.replace("#", "")
102106
}
103107

108+
data5 = {
109+
"name": "first-release",
110+
"description": "first release",
111+
"color": color4.replace("#", "")
112+
}
113+
data6 = {
114+
"name": "major",
115+
"description": "major release",
116+
"color": color4.replace("#", "")
117+
}
118+
data7 = {
119+
"name": "minor",
120+
"description": "minor release",
121+
"color": color4.replace("#", "")
122+
}
123+
data8 = {
124+
"name": "patch",
125+
"description": "patch update",
126+
"color": color4.replace("#", "")
127+
}
128+
104129
response1 = requests.post(url=api_endpoint, headers=headers, json=data1)
105130
status_code1 = response1.status_code
106131
response2 = requests.post(url=api_endpoint, headers=headers, json=data2)
@@ -109,12 +134,24 @@ def create_new_label(repo_names: list[str], org_name: str):
109134
status_code3 = response3.status_code
110135
response4 = requests.post(url=api_endpoint, headers=headers, json=data4)
111136
status_code4 = response4.status_code
137+
response5 = requests.post(url=api_endpoint, headers=headers, json=data1)
138+
status_code5 = response5.status_code
139+
response6 = requests.post(url=api_endpoint, headers=headers, json=data1)
140+
status_code6 = response6.status_code
141+
response7 = requests.post(url=api_endpoint, headers=headers, json=data1)
142+
status_code7 = response7.status_code
143+
response8 = requests.post(url=api_endpoint, headers=headers, json=data1)
144+
status_code8 = response8.status_code
112145
response1_json =response1.json()
113146
# print(response1_json)
114147
response2_json =response2.json()
115148
# print(response2_json)
116149
response3_json =response3.json()
117150
response4_json =response4.json()
151+
response5_json = response5.json()
152+
response6_json = response6.json()
153+
response7_json = response7.json()
154+
response8_json = response8.json()
118155

119156

120157
# data 1
@@ -158,6 +195,48 @@ def create_new_label(repo_names: list[str], org_name: str):
158195
# print(f'Validation failed, or the endpoint has been spammed')
159196
else:
160197
print('Something is wrong. Please try again')
198+
# data 5
199+
if status_code5 == 201:
200+
print(f'New label {data5["name"]} created for repository - {repository}')
201+
elif status_code5 == 404:
202+
print(f'Resource not found')
203+
elif status_code5 == 422:
204+
print(f"{response5_json['message']}. {response5_json['errors'][0]['resource']} {response5_json['errors'][0]['field']} {data5['name']} {response5_json['errors'][0]['code']} in the repository {repository}")
205+
# print(f'Validation failed, or the endpoint has been spammed')
206+
else:
207+
print('Something is wrong. Please try again')
208+
# data 6
209+
if status_code6 == 201:
210+
print(f'New label {data6["name"]} created for repository - {repository}')
211+
elif status_code6 == 404:
212+
print(f'Resource not found')
213+
elif status_code6 == 422:
214+
print(f"{response6_json['message']}. {response6_json['errors'][0]['resource']} {response6_json['errors'][0]['field']} {data6['name']} {response6_json['errors'][0]['code']} in the repository {repository}")
215+
# print(f'Validation failed, or the endpoint has been spammed')
216+
else:
217+
print('Something is wrong. Please try again')
218+
# data 7
219+
if status_code7 == 201:
220+
print(f'New label {data7["name"]} created for repository - {repository}')
221+
elif status_code7 == 404:
222+
print(f'Resource not found')
223+
elif status_code7 == 422:
224+
print(f"{response7_json['message']}. {response7_json['errors'][0]['resource']} {response7_json['errors'][0]['field']} {data7['name']} {response7_json['errors'][0]['code']} in the repository {repository}")
225+
# print(f'Validation failed, or the endpoint has been spammed')
226+
else:
227+
print('Something is wrong. Please try again')
228+
229+
# data 8
230+
if status_code8 == 201:
231+
print(f'New label {data8["name"]} created for repository - {repository}')
232+
elif status_code8 == 404:
233+
print(f'Resource not found')
234+
elif status_code8 == 422:
235+
print(f"{response8_json['message']}. {response8_json['errors'][0]['resource']} {response8_json['errors'][0]['field']} {data8['name']} {response8_json['errors'][0]['code']} in the repository {repository}")
236+
# print(f'Validation failed, or the endpoint has been spammed')
237+
else:
238+
print('Something is wrong. Please try again')
239+
161240

162241
def main():
163242
""" To test the script"""

0 commit comments

Comments
 (0)