Skip to content

Commit badeef0

Browse files
DEVOPS-68 initial commit
1 parent 3f6e043 commit badeef0

File tree

6 files changed

+543
-1
lines changed

6 files changed

+543
-1
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,4 +157,4 @@ cython_debug/
157157
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
158158
# and can be added to the global gitignore or merged into this file. For a more nuclear
159159
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
160-
#.idea/
160+
.idea/

date_time.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from datetime import datetime
2+
3+
def date_time():
4+
"""return current date time formatted"""
5+
now = datetime.now()
6+
formatted_datetime = now.strftime("%d-%B-%Y %H:%M")
7+
return formatted_datetime
8+
# print(formatted_datetime)
9+
10+
def main():
11+
""" test code """
12+
date_time()
13+
14+
if __name__ == "__main__":
15+
main()

github_scanning.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import os
2+
from dotenv import load_dotenv
3+
from jira import create_story_under_epic
4+
from date_time import date_time
5+
import requests
6+
7+
def scan_for_dependabot_alerts_and_issues(organization: str, repository: str):
8+
"""
9+
scan github for github security scans and issues
10+
:return:
11+
"""
12+
api_endpoint = f'https://api.github.com/repos/{organization}/{repository}/dependabot/alerts'
13+
headers = {
14+
"Accept": "application/vnd.github+json",
15+
"Authorization": f"Bearer {os.getenv('GH_TOKEN')}",
16+
"X-GitHub-Api-Version": "2022-11-28"
17+
}
18+
response = requests.get(url=api_endpoint, headers=headers)
19+
response_json = response.json()
20+
print(response_json)
21+
issues_list = []
22+
for issue in response_json:
23+
dict = {}
24+
dict['dependancy'] = issue['dependency']['package']
25+
dict['issue_is_at'] = issue['dependency']['manifest_path']
26+
dict['cve_id'] = issue['security_advisory']['cve_id']
27+
dict['issue_summary'] = issue['security_advisory']['summary']
28+
dict['issue_description'] = issue['security_advisory']['description']
29+
dict['issue_severity'] = issue['security_advisory']['severity']
30+
dict['issue_created_at'] = issue['created_at']
31+
32+
# add dict to list
33+
issues_list.append(dict)
34+
print(issues_list)
35+
36+
return issues_list
37+
38+
def main():
39+
"""To test the scripts"""
40+
load_dotenv()
41+
organization = 'devwithkrishna'
42+
repository = 'programatically-create-delete-update-github-repository-secrets'
43+
44+
issues_list = scan_for_dependabot_alerts_and_issues(organization=organization, repository=repository)
45+
for issues in issues_list:
46+
summary = f"{issues['cve_id']} {repository} - {issues['issue_severity']} - {issues['issue_summary']}"
47+
description = f"{issues['issue_description']} \n 'Issue Created at' - {issues['issue_created_at']}"
48+
story = create_story_under_epic(epic_key='DEVOPS-74', summary=summary, description=description)
49+
print(f"Created story {story['key']} at {date_time()} IST")
50+
51+
52+
if __name__ == "__main__":
53+
main()

jira.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import os
2+
import json
3+
import requests
4+
from dotenv import load_dotenv
5+
from atlassian import Jira
6+
7+
# Initializing jira client
8+
load_dotenv()
9+
JIRA_URL = os.getenv('JIRA_URL')
10+
JIRA_USERNAME = os.getenv('JIRA_USERNAME')
11+
JIRA_PASSWORD = os.getenv('JIRA_PASSWORD')
12+
13+
14+
15+
# Function to create a story under a specific epic
16+
def create_story_under_epic(epic_key, summary, description):
17+
issue_dict = {
18+
'project': {'key': 'DEVOPS'},
19+
'summary': summary,
20+
'description': description,
21+
'issuetype': {'name': 'Task'},
22+
'parent': {
23+
"key": epic_key
24+
}
25+
}
26+
new_issue = jira.issue_create(fields=issue_dict)
27+
# pic = new_issue.update(fields={'parent': {'id': epic_key}})
28+
29+
return new_issue
30+
31+
32+
def issues_in_epic(epic_key: str, board_id: int):
33+
"""
34+
list available issues in a epic
35+
:param epic_key:
36+
:return:
37+
"""
38+
jira = Jira(url=os.getenv('JIRA_URL'), username=os.getenv('JIRA_USERNAME'), password=os.getenv('JIRA_PASSWORD'),
39+
cloud=True)
40+
41+
# todo
42+
43+
def get_board_id(project_key: str):
44+
# jira = Jira(url=os.getenv('JIRA_URL_0'), username=os.getenv('JIRA_USERNAME'), password=os.getenv('JIRA_PASSWORD'),
45+
# cloud=True)
46+
response = requests.get(url=os.getenv('JIRA_URL_0'),auth=(os.getenv('JIRA_USERNAME'), os.getenv('JIRA_PASSWORD')))
47+
if response.status_code == 200:
48+
boards = response.json()['values']
49+
if boards:
50+
# Assuming you want the first board ID
51+
return boards[0]['id']
52+
return None
53+
54+
def main():
55+
"""testing script"""
56+
# Replace these values with your specific details
57+
epic_key = 'DEVOPS-74'
58+
summary = 'New Story Summary135'
59+
description = 'Description -- of the new story'
60+
61+
# Create the story
62+
# story = create_story_under_epic(epic_key, summary, description)
63+
# print(f"Created story {story['key']} under epic {epic_key}")
64+
65+
# List stories under an epic
66+
stories = issues_in_epic(epic_key=epic_key, board_id=1)
67+
68+
# get_board_id('DEVOPS')
69+
70+
if __name__ == "__main__":
71+
main()

0 commit comments

Comments
 (0)