Skip to content

Commit

Permalink
tools: add changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
gsanchietti committed Apr 29, 2024
1 parent 615c01e commit 7eaac63
Show file tree
Hide file tree
Showing 2 changed files with 145 additions and 0 deletions.
23 changes: 23 additions & 0 deletions tools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,26 @@ Bumped packages can then be installed directly from the repository.

The script searches only for ns-* packages that it bumps the version and creates a commit for each package.
Finally it pushes the commits and creates a PR.

## changelog

Create a changelog in JSON format from a given GitHub project.
It searches all the cards inside the the column that starts with the given name (default is "Done").

Usage example:
```
GITHUB_ORG=nethserver GITHUB_PROJECT=10 GITHUB_TOKEN=xxxxxx COLUMN_NAME=Done ./changelog
```

You can pass the obtained JSON to ChatGPT (or another model) with a prompt like:
```
Create a detailed changelog from the below JSON file.
Split the changes between new features and bug fixes.
Make sure to include all changes.
Use this template for each record:
- This is the title: this is a brief description in one line
Do not use capital letter after column char.
Do not include links to external resources.
```
122 changes: 122 additions & 0 deletions tools/changelog
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
#!/usr/bin/python

import requests
import json
import sys
import os

# GitHub organization and project ID
org = os.environ.get("GITHUB_ORG", "")
if not org:
sys.exit("GitHub organization not found")
project_id = os.environ.get("GITHUB_PROJECT_ID", "10")
if not project_id:
sys.exit("GitHub project ID not found")

# GitHub token (replace 'YOUR_TOKEN' with your personal access token)
github_token = os.environ.get("GITHUB_TOKEN", "")
if not github_token:
sys.exit("GitHub token not found")

column_name = os.environ.get("COLUMN_NAME", "Done")

# GraphQL queries
query_id = '''
query {
organization(login: "%s") {
projectV2(number: %s) {
id
}
}
}
''' % (org, project_id)

query_items = '''
query {
node(id: "%s") {
... on ProjectV2 {
items(first: 100) {
nodes {
id
fieldValues(first: 8) {
nodes {
... on ProjectV2ItemFieldTextValue {
text
field {
... on ProjectV2FieldCommon {
name
}
}
}
... on ProjectV2ItemFieldDateValue {
date
field {
... on ProjectV2FieldCommon {
name
}
}
}
... on ProjectV2ItemFieldSingleSelectValue {
name
field {
... on ProjectV2FieldCommon {
name
}
}
}
}
}
content {
... on DraftIssue {
title
body
}
... on Issue {
title
body
}
... on PullRequest {
title
body
}
}
}
}
}
}
}
'''


# GitHub API endpoint
api_endpoint = "https://api.github.com/graphql"

# Construct request headers with authorization token
headers = {
"Authorization": f"Bearer {github_token}",
"Accept": "application/json"
}

# Function to make a GraphQL request
def graphql_request(query):
response = requests.post(api_endpoint, json={"query": query}, headers=headers)
return response.json()

# Get project ID
response_id = graphql_request(query_id)
project_id = response_id["data"]["organization"]["projectV2"]["id"]

# Get project items
response_items = graphql_request(query_items % project_id)['data']['node']['items']['nodes']
issues = []
for item in response_items:
issue = {"title": "", "body": ""}
for node in item['fieldValues']['nodes']:
if 'field' in node and node['field'].get('name', '') == 'Status':
if node.get('name').startswith(column_name):
issue['title'] = item['content']['title']
issue['body'] = item['content']['body']
issues.append(issue)
continue

print(json.dumps(issues, indent=2))

0 comments on commit 7eaac63

Please sign in to comment.