Skip to content

Commit a6d6e66

Browse files
DEVOPS-72 added dependabot workflow and modified py porgm
1 parent b1e706e commit a6d6e66

File tree

3 files changed

+109
-2
lines changed

3 files changed

+109
-2
lines changed

.github/dependabot.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "pip"
4+
directory: /
5+
schedule:
6+
interval: "weekly"
7+
day: wednesday
8+
time: "11:38"
9+
timezone: Asia/Kolkata
10+
# Assignees to set on pull requests
11+
assignees:
12+
- "githubofkrishnadhas"
13+
# prefix specifies a prefix for all commit messages. When you specify a prefix for commit messages,
14+
# GitHub will automatically add a colon between the defined prefix and the commit message provided the
15+
# defined prefix ends with a letter, number, closing parenthesis, or closing bracket.
16+
commit-message:
17+
prefix: "dependabot python package"
18+
# Use reviewers to specify individual reviewers or teams of reviewers for all pull requests raised for a package manager.
19+
reviewers:
20+
- "devwithkrishna/admin"
21+
# Raise pull requests for version updates to pip against the `main` branch
22+
target-branch: "main"
23+
# Labels on pull requests for version updates only
24+
labels:
25+
- "pip dependencies"
26+
- "pip-package"
27+
# Increase the version requirements for Composer only when required
28+
versioning-strategy: increase-if-necessary
29+
# Dependabot opens a maximum of five pull requests for version updates. Once there are five open pull requests from Dependabot,
30+
# Dependabot will not open any new requests until some of those open requests are merged or closed.
31+
# Use open-pull-requests-limit to change this limit.
32+
open-pull-requests-limit: 10
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: github-create-and-add-labels-all-repos-using-python
2+
on:
3+
schedule:
4+
- cron: "0 9 * * 2" # runs weekly at 9 AM on Tuesday
5+
workflow_dispatch:
6+
inputs:
7+
organizarion:
8+
description: 'GitHub organization name'
9+
required: true
10+
type: string
11+
default: 'devwithkrishna'
12+
13+
jobs:
14+
github-create-and-add-labels-all-repos-using-python:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: git checkout
18+
uses: actions/checkout@v4
19+
- name: set up python 3.11
20+
uses: actions/setup-python@v4
21+
with:
22+
python-version: '3.11'
23+
- name: package installations
24+
run: |
25+
pip install poetry
26+
poetry install
27+
- name: execute python program
28+
env:
29+
org_name: 'devwithkrishna'
30+
run: |
31+
poetry run python3 create_new_labels.py
32+
- name: Completed
33+
run: |
34+
echo "program completed successfully"

create_new_labels.py

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ def create_new_label(repo_names: list[str], org_name: str):
4444

4545
color1 = random.choice(colors)
4646
color2 = random.choice(colors)
47+
color3 = random.choice(colors)
48+
color4 = random.choice(colors)
4749
for repository in repo_names:
4850
api_endpoint=f'https://api.github.com/repos/{org_name}/{repository}/labels'
4951

@@ -65,15 +67,35 @@ def create_new_label(repo_names: list[str], org_name: str):
6567
"color": color2.replace("#", "")
6668
}
6769

70+
data3 = {
71+
"name": "jenkins",
72+
"description": "jenkins ci cd",
73+
"color" : color3.replace("#", "")
74+
}
75+
76+
data4 = {
77+
"name": "docker",
78+
"description": "docker",
79+
"color": color4.replace("#", "")
80+
}
81+
6882
response1 = requests.post(url=api_endpoint, headers=headers, json=data1)
6983
status_code1 = response1.status_code
7084
response2 = requests.post(url=api_endpoint, headers=headers, json=data2)
7185
status_code2 = response2.status_code
86+
response3 = requests.post(url=api_endpoint, headers=headers, json=data3)
87+
status_code3 = response3.status_code
88+
response4 = requests.post(url=api_endpoint, headers=headers, json=data4)
89+
status_code4 = response4.status_code
7290
response1_json =response1.json()
7391
# print(response1_json)
7492
response2_json =response2.json()
7593
# print(response2_json)
94+
response3_json =response3.json()
95+
response4_json =response4.json()
7696

97+
98+
# data 1
7799
if status_code1 == 201:
78100
print(f'New label {data1["name"]} created for repository - {repository}')
79101
elif status_code1 == 404:
@@ -83,7 +105,7 @@ def create_new_label(repo_names: list[str], org_name: str):
83105
# print(f'Validation failed, or the endpoint has been spammed')
84106
else:
85107
print('Something is wrong. Please try again')
86-
108+
# data2
87109
if status_code2 == 201:
88110
print(f'New label {data2["name"]} created for repository - {repository}')
89111
elif status_code2 == 404:
@@ -93,8 +115,27 @@ def create_new_label(repo_names: list[str], org_name: str):
93115
# print(f'Validation failed, or the endpoint has been spammed')
94116
else:
95117
print('Something is wrong. Please try again')
118+
# data3
119+
if status_code3 == 201:
120+
print(f'New label {data3["name"]} created for repository - {repository}')
121+
elif status_code3 == 404:
122+
print(f'Resource not found')
123+
elif status_code3 == 422:
124+
print(f"{response3_json['message']}. {response3_json['errors'][0]['resource']} {response3_json['errors'][0]['field']} {data3['name']} {response3_json['errors'][0]['code']} in the repository {repository}")
125+
# print(f'Validation failed, or the endpoint has been spammed')
126+
else:
127+
print('Something is wrong. Please try again')
128+
# data4
96129

97-
130+
if status_code4 == 201:
131+
print(f'New label {data4["name"]} created for repository - {repository}')
132+
elif status_code4 == 404:
133+
print(f'Resource not found')
134+
elif status_code4 == 422:
135+
print(f"{response4_json['message']}. {response4_json['errors'][0]['resource']} {response4_json['errors'][0]['field']} {data4['name']} {response4_json['errors'][0]['code']} in the repository {repository}")
136+
# print(f'Validation failed, or the endpoint has been spammed')
137+
else:
138+
print('Something is wrong. Please try again')
98139

99140
def main():
100141
""" To test the script"""

0 commit comments

Comments
 (0)