Skip to content

Commit 0f6da17

Browse files
authored
Merge pull request #3 from KjellKod/jira_metrics
Jira metrics
2 parents 47464d2 + 7a72232 commit 0f6da17

24 files changed

+206
-8
lines changed

README.txt

Lines changed: 0 additions & 8 deletions
This file was deleted.

github/releases.py

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import os
2+
import requests
3+
from collections import defaultdict
4+
5+
# Retrieve the access token from the environment variable
6+
access_token = os.environ.get('GITHUB_TOKEN_READONLY_WEB')
7+
8+
# Set the repository owner and name
9+
owner = os.environ.get('GITHUB_METRIC_OWNER')
10+
repo = on.environ.get('GITHUB_METRIC_REPO')
11+
12+
# Set the API endpoint URL
13+
url = f'https://api.github.com/repos/{owner}/{repo}/tags'
14+
15+
# Set the request headers
16+
headers = {
17+
'Authorization': f'token {access_token}',
18+
'Accept': 'application/vnd.github.v3+json'
19+
}
20+
21+
# Set the query parameters
22+
params = {
23+
'per_page': 100, # Number of items per page
24+
'since': '2022-12-31T23:59:59Z' # Filter releases after 2023-12
25+
}
26+
27+
# Create a dictionary to store releases by year and month
28+
releases_by_month = defaultdict(list)
29+
30+
# Retrieve releases from all pages
31+
while url:
32+
# Send a GET request to retrieve the tags
33+
response = requests.get(url, headers=headers, params=params)
34+
35+
# Check if the request was successful
36+
if response.status_code == 200:
37+
# Parse the JSON response
38+
tags = response.json()
39+
40+
# Sort the releases into the dictionary
41+
for tag in tags:
42+
if tag['name'].startswith('release-'):
43+
release_date = tag['name'].split('release-')[1]
44+
year_month = release_date[:7]
45+
releases_by_month[year_month].append(tag['name'])
46+
47+
# Check if there are more pages
48+
if 'next' in response.links:
49+
url = response.links['next']['url']
50+
else:
51+
url = None
52+
else:
53+
print(f'Error: {response.status_code} - {response.text}')
54+
break
55+
56+
# Print the releases enumerated by year and month with the month sum
57+
for year_month, releases in sorted(releases_by_month.items()):
58+
year, month = year_month.split('-')
59+
month_sum = len(releases)
60+
print(f"{year}-{month}: {month_sum}")
61+
for index, release in enumerate(releases, start=1):
62+
print(f" {index}. {release}")
63+
print()
64+
65+
66+
# # Send a GET request to retrieve the tags
67+
# response = requests.get(url, headers=headers)
68+
69+
# # Check if the request was successful
70+
# if response.status_code == 200:
71+
# # Parse the JSON response
72+
# tags = response.json()
73+
74+
# # Create a dictionary to store releases by year and month
75+
# releases_by_month = defaultdict(list)
76+
77+
# # Sort the releases into the dictionary
78+
# for tag in tags:
79+
# if tag['name'].startswith('release-'):
80+
# release_date = tag['name'].split('release-')[1]
81+
# year_month = release_date[:7]
82+
# releases_by_month[year_month].append(tag['name'])
83+
84+
# # Print the releases enumerated by year and month
85+
# for year_month, releases in sorted(releases_by_month.items()):
86+
# year, month = year_month.split('-')
87+
# month_sum = len(releases)
88+
# print(f"{year}-{month}: {month_sum}")
89+
# for index, release in enumerate(releases, start=1):
90+
# print(f" {index}. {release}")
91+
# print()
92+
# else:
93+
# print(f'Error: {response.status_code} - {response.text}')

jira/README.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
install the jiradoodles package in edit mode will fix unit test issues
2+
=====================
3+
pip install -e .
4+
5+
run unit test
6+
============
7+
python3 -m unittest discover -s test
8+
9+
10+
11+
12+
jira_metrics/
13+
14+
├── bin/ # Directory for executable scripts
15+
│ ├── extract_metadata.py
16+
│ ├── extract_performance.py
17+
│ └── ...
18+
19+
├── jira_metrics/ # Main package directory
20+
│ ├── __init__.py # Makes jira_metrics a Python package
21+
│ ├── config.py # Configuration settings and constants
22+
│ ├── utilities/ # Utility modules
23+
│ │ ├── __init__.py
24+
│ │ ├── time_utils.py
25+
│ │ ├── io_utils.py
26+
│ │ ├── json_utils.py
27+
│ │ ├── jira_query.py
28+
│ │ └── ...
29+
│ ├── metrics/ # Modules for specific metrics extraction
30+
│ │ ├── __init__.py
31+
32+
│ │ ├── sprint_metadata.py
33+
│ │ ├── performance_metrics.py
34+
│ │ └── ...
35+
│ └── data/ # For storing local data files, if necessary
36+
37+
├── tests/ # Test suite
38+
│ ├── __init__.py
39+
│ ├── test_time_utils.py
40+
│ ├── test_io_utils.py
41+
│ ├── test_json_utils.py
42+
│ ├── test_jira_query.py
43+
│ └── ...
44+
45+
├── .gitignore # Specifies intentionally untracked files to ignore
46+
├── requirements.txt # Fixed versions of dependencies
47+
└── README.md # Project overview and setup instructions
48+
49+
50+
Key Components
51+
bin/: This directory contains executable scripts that users can run. Each script uses functionalities from the jira_metrics package. These scripts are the entry points for different tasks like extracting metadata or performance metrics.
52+
jira_metrics/: The main package containing all the modular code.
53+
config.py: Central configuration file for managing constants like API keys, URLs, etc.
54+
utilities/: Utility modules that provide common functionalities like handling time and dates, I/O operations, and Jira queries.
55+
metrics/: Modules dedicated to extracting specific metrics from Jira.
56+
tests/: Contains all unit tests. Each utility and metrics module should have corresponding test modules here.
57+
58+
Development Practices
59+
Modularity: Keep the code modular. Each utility should have a single responsibility and should be independent as much as possible.
60+
Testing: Aim for high test coverage. Mock external dependencies like Jira API responses.
61+
Documentation: Each module, class, and method should have clear docstrings explaining what it does. The README should provide clear setup and usage instructions.
62+
Version Control: Use Git for version control. Include a .gitignore file to exclude unnecessary files (like __pycache__).
63+
64+
Setup Files
65+
init_.py: Necessary in each directory that you want to treat as a Python package. This can be empty or can include package imports.
66+
requirements.txt: List all the dependencies with versions that are known to work with your application.
67+
This structure should provide a solid foundation for building and scaling your Jira metrics extraction tool while keeping the code organized and maintainable.

jira/bin/extract_metrics.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import os
2+
import json
3+
from jira import JIRA
4+
#from jira_metrics.utilities.jira_query import create_jql_query
5+
6+
def setup_jira_instance():
7+
jira_api_key = os.getenv("JIRA_API_KEY")
8+
jira_link = os.getenv("JIRA_LINK")
9+
user_email = os.getenv("USER_EMAIL")
10+
11+
if not all([jira_api_key, jira_link, user_email]):
12+
raise EnvironmentError("Missing one or more environment variables: JIRA_API_KEY, JIRA_LINK, USER_EMAIL")
13+
14+
options = {'server': jira_link}
15+
jira = JIRA(options, basic_auth=(user_email, jira_api_key))
16+
return jira
17+
18+
def read_queries_from_file(file_path):
19+
with open(file_path, 'r') as file:
20+
queries = json.load(file)
21+
return queries
22+
23+
def fetch_tickets(jira, query):
24+
issues = jira.search_issues(query, maxResults=-1)
25+
return issues
26+
27+
def main():
28+
jira = setup_jira_instance()
29+
queries = read_queries_from_file('queries/queries.json')
30+
31+
for query in queries:
32+
issues = fetch_tickets(jira, query['jql'])
33+
print(f"Found {len(issues)} issues for query: {query['description']}")
34+
35+
if __name__ == "__main__":
36+
main()

jira/jira_metrics/__init__.py

Whitespace-only changes.

jira/jira_metrics/config.py

Whitespace-only changes.

jira/jira_metrics/utilities/__init__.py

Whitespace-only changes.

jira/jira_metrics/utilities/io_utils.py

Whitespace-only changes.

jira/jira_metrics/utilities/jira_query.py

Whitespace-only changes.

jira/jira_metrics/utilities/json_utils.py

Whitespace-only changes.

0 commit comments

Comments
 (0)