Thanks to visit codestin.com
Credit goes to github.com

Skip to content

update repo to rollout labels to all repos as a cron #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/workflows/create-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: create release on labels automation repo

on:
pull_request:
types:
- closed
branches:
- main
run-name: create release from pr number ${{ github.event.number }}
jobs:
create-release:
runs-on: ubuntu-latest

steps:

- name: Token generator
uses: githubofkrishnadhas/github-access-using-githubapp@v2
id: token-generation
with:
github_app_id: ${{ secrets.TOKEN_GENERATOR_APPID }}
github_app_private_key: ${{ secrets.TOKEN_GENERATOR_PRIVATE_KEY }}

- name: Checkout Repository
uses: actions/checkout@v4
with:
token: ${{ steps.token-generation.outputs.token }}

- name: create-release
uses: devwithkrishna/[email protected]
with:
token: ${{ steps.token-generation.outputs.token }}
pr_number: ${{ github.event.number }}
generate_release_notes: true
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: github-create-and-add-labels-all-repos-using-python
on:
schedule:
- cron: "0 9 * * 2" # runs weekly at 9 AM on Tuesday
- cron: "0 9 * * *" # runs daily at 9 AM utc
workflow_dispatch:
inputs:
organizarion:
Expand Down
81 changes: 80 additions & 1 deletion create_new_labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def list_repos_in_org(org_name: str):
for repo in all_repositories:
print(repo['name'])
repo_names.append(repo['name'])

print(f"Found {len(repo_names)} in {org_name}")
print(f'Listing Public repos in {org_name} completed')
return repo_names

Expand All @@ -68,6 +68,10 @@ def create_new_label(repo_names: list[str], org_name: str):
color2 = random.choice(colors)
color3 = random.choice(colors)
color4 = random.choice(colors)
color5 = random.choice(colors)
color6 = random.choice(colors)
color7 = random.choice(colors)
color8 = random.choice(colors)
for repository in repo_names:
api_endpoint=f'https://api.github.com/repos/{org_name}/{repository}/labels'

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

data5 = {
"name": "first-release",
"description": "first release",
"color": color4.replace("#", "")
}
data6 = {
"name": "major",
"description": "major release",
"color": color4.replace("#", "")
}
data7 = {
"name": "minor",
"description": "minor release",
"color": color4.replace("#", "")
}
data8 = {
"name": "patch",
"description": "patch update",
"color": color4.replace("#", "")
}

response1 = requests.post(url=api_endpoint, headers=headers, json=data1)
status_code1 = response1.status_code
response2 = requests.post(url=api_endpoint, headers=headers, json=data2)
Expand All @@ -109,12 +134,24 @@ def create_new_label(repo_names: list[str], org_name: str):
status_code3 = response3.status_code
response4 = requests.post(url=api_endpoint, headers=headers, json=data4)
status_code4 = response4.status_code
response5 = requests.post(url=api_endpoint, headers=headers, json=data1)
status_code5 = response5.status_code
response6 = requests.post(url=api_endpoint, headers=headers, json=data1)
status_code6 = response6.status_code
response7 = requests.post(url=api_endpoint, headers=headers, json=data1)
status_code7 = response7.status_code
response8 = requests.post(url=api_endpoint, headers=headers, json=data1)
status_code8 = response8.status_code
response1_json =response1.json()
# print(response1_json)
response2_json =response2.json()
# print(response2_json)
response3_json =response3.json()
response4_json =response4.json()
response5_json = response5.json()
response6_json = response6.json()
response7_json = response7.json()
response8_json = response8.json()


# data 1
Expand Down Expand Up @@ -158,6 +195,48 @@ def create_new_label(repo_names: list[str], org_name: str):
# print(f'Validation failed, or the endpoint has been spammed')
else:
print('Something is wrong. Please try again')
# data 5
if status_code5 == 201:
print(f'New label {data5["name"]} created for repository - {repository}')
elif status_code5 == 404:
print(f'Resource not found')
elif status_code5 == 422:
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}")
# print(f'Validation failed, or the endpoint has been spammed')
else:
print('Something is wrong. Please try again')
# data 6
if status_code6 == 201:
print(f'New label {data6["name"]} created for repository - {repository}')
elif status_code6 == 404:
print(f'Resource not found')
elif status_code6 == 422:
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}")
# print(f'Validation failed, or the endpoint has been spammed')
else:
print('Something is wrong. Please try again')
# data 7
if status_code7 == 201:
print(f'New label {data7["name"]} created for repository - {repository}')
elif status_code7 == 404:
print(f'Resource not found')
elif status_code7 == 422:
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}")
# print(f'Validation failed, or the endpoint has been spammed')
else:
print('Something is wrong. Please try again')

# data 8
if status_code8 == 201:
print(f'New label {data8["name"]} created for repository - {repository}')
elif status_code8 == 404:
print(f'Resource not found')
elif status_code8 == 422:
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}")
# print(f'Validation failed, or the endpoint has been spammed')
else:
print('Something is wrong. Please try again')


def main():
""" To test the script"""
Expand Down