Skip to content

Commit

Permalink
updated code to get all release notes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerome1998 committed May 1, 2024
1 parent f120c96 commit 1c7e35e
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 92 deletions.
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"files.associations": {
"*.yaml": "home-assistant"
}
}
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 Kellojo
Copyright (c) 2024 Jerome1998

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
51 changes: 32 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,42 +1,55 @@
# github-release-notes-generator

A small little node module that converts release notes of github releases into a `json` format

This action is based on the idea of @Kellojo, so basically all the credits belong to him.
I modified his code to get all the release notes and not only a specific version.

It creates a json file with the following contents:
```
{
"name": "Now featuring Planned Transactions",
"url": "https://github.com/Kellojo/Budget-Book/releases/tag/untagged-605ac3664b967afc4552",
"version": "v1.3.0",
"creationDate": "2021-02-07T13:36:50Z",
"releaseDate": "2021-05-22T12:37:31.093Z",
"description": "In this release, you can now start planning recurring transactions with the new transaction planning feature.\r\nThis way you can easily automate your income and expense tracking for recurring payments (i.e. rent, salary, etc.).\r\nTransactions can be planned to recur on a daily, weekly, monthly, yearly basis.\r\n\r\nOther smaller enhancements have been added:\r\n- Besides that you can now find the used open source packages in the user help menu.\r\n- The onboarding has been updated to showcase the features of the app\r\n- Some smaller UI enhancements have been added\r\n- The app is now signed and notarized for (Mac OS only). This makes installation easier, as Mac OS will no longer show it as an untrusted app. \r\n- The MIT license has been removed and the project is from now on licensed under the [Commons Clause license](https://commonsclause.com/)",
"author": "Kellojo",
"authorAvatar": "https://avatars.githubusercontent.com/u/12833426?v=4"
}

```json
[
{
"name": "Now featuring Planned Transactions",
"url": "https://github.com/Kellojo/Budget-Book/releases/tag/untagged-605ac3664b967afc4552",
"version": "v1.3.0",
"creationDate": "2021-02-07T13:36:50Z",
"releaseDate": "2021-05-22T12:37:31.093Z",
"description": "In this release, you can now start planning recurring transactions with the new transaction planning feature.\r\nThis way you can easily automate your income and expense tracking for recurring payments (i.e. rent, salary, etc.).\r\nTransactions can be planned to recur on a daily, weekly, monthly, yearly basis.\r\n\r\nOther smaller enhancements have been added:\r\n- Besides that you can now find the used open source packages in the user help menu.\r\n- The onboarding has been updated to showcase the features of the app\r\n- Some smaller UI enhancements have been added\r\n- The app is now signed and notarized for (Mac OS only). This makes installation easier, as Mac OS will no longer show it as an untrusted app. \r\n- The MIT license has been removed and the project is from now on licensed under the [Commons Clause license](https://commonsclause.com/)",
"author": "Kellojo",
"authorAvatar": "https://avatars.githubusercontent.com/u/12833426?v=4"
},
{
"name": "Cool Release",
"url": "https://github.com/Kellojo/Budget-Book/releases/tag/untagged-605ac3664b967afc4552",
"version": "v1.2.0",
"creationDate": "2021-02-06T12:35:40Z",
"releaseDate": "2021-0-22T12:37:31.093Z",
"description": "Some cool release notes",
"author": "Kellojo",
"authorAvatar": "https://avatars.githubusercontent.com/u/12833426?v=4"
}
]
```

This file can then be used to i.e. create a release notes dialog within an app or something else.


## Inputs

### `github-access-token`

**Required** The GitHub access token. This is required to create the release notes. Default ``.

### `destination`
**Required** Where should the resulting release notes be saved to (i.e. `./config/release-notes.json`)? Default ``.

### `version`
The version to create the release notes for. If none is supplied, the package.json is read to get the version.

**Required** Where should the resulting release notes be saved to (i.e. `./config/release-notes.json`)? Default ``.

## Example usage

```
```yaml
- name: Create Release Notes
uses: Kellojo/github-release-notes-generator@v1.4
uses: Jerome1998/github-release-notes-generator@v1.0
with:
destination: './config/release-notes.json'
github-access-token: ${{ secrets.github_token }}
github-access-token: ${{ secrets.GITHUB_TOKEN }}
```
10 changes: 4 additions & 6 deletions action.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
name: 'GitHub Release Notes JSON Generator'
description: 'A small little GitHub action that converts release notes of github releases into a json format'

inputs:
version:
description: 'Which version should we delete the assets from?'
required: false
default: ''
destination:
description: 'Where should the resulting release notes be saved to (i.e. `./config/release-notes.json`)'
required: true
Expand All @@ -13,10 +10,11 @@ inputs:
description: 'The GitHub access token required to delete the assets & discover non released versions'
required: true
default: ''

runs:
using: 'node12'
using: 'node20'
main: 'index.js'

branding:
icon: 'bookmark'
color: 'gray-dark'
31 changes: 6 additions & 25 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,23 @@
const core = require('@actions/core');
const github = require('@actions/github');
const {ReleaseNotesGenerator} = require("./release-notes-generator");
const fs = require('fs');

const readPackageJson = function () {
const sFile = fs.readFileSync('./package.json').toString();

try {
return JSON.parse(sFile);
} catch (error) {

}

return null;
}
const core = require("@actions/core");
const github = require("@actions/github");
const { ReleaseNotesGenerator } = require("./release-notes-generator");

const sRepo = github.context.repo.repo;
const sOwner = github.context.repo.owner
const sVersion = core.getInput("version") || readPackageJson().version;
const sAuthToken = core.getInput("github-access-token");
const sFilePath = core.getInput("destination");

if (!sRepo) { core.error("no repository specified, aborting"); }
if (!sOwner) { core.error("no owner specified, aborting"); }
if (!sVersion) { core.error("no version specified, aborting"); }
if (!sAuthToken) { core.error("no GitHub access token specified, aborting"); }





const run = async function () {
new ReleaseNotesGenerator(sAuthToken, sOwner, sRepo, sVersion).createReleaseNotes(sFilePath);
new ReleaseNotesGenerator(sAuthToken, sOwner, sRepo).createReleaseNotes(sFilePath);
}

try {
run();
run();
} catch (error) {
core.setFailed(error.message);
core.setFailed(error.message);
}

78 changes: 37 additions & 41 deletions release-notes-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,41 @@ const { Octokit } = require("@octokit/rest");
const fs = require("fs");

module.exports.ReleaseNotesGenerator = class ReleaseNotesGenerator {

constructor(sAuthToken, sOwner, sRepo, sVersion) {
this.owner = sOwner;
this.repo = sRepo;
this.version = sVersion;

this.octokit = new Octokit({
auth: sAuthToken,
});
}

async createReleaseNotes (sFilePath) {
const oRelease = await this.getReleaseInfos(this.owner, this.repo);
this.writeInfosToFile(oRelease, sFilePath);
}

async getReleaseInfos (sOwner, sRepo) {
const { data } = await this.octokit.request(`/repos/${sOwner}/${sRepo}/releases`);
const oCurrentRelease = data.find(oRelease => oRelease.tag_name.includes(this.version));
return oCurrentRelease;
}
writeInfosToFile (oRelease, sFilePath) {
console.log(`Found ${oRelease.tag_name} ${oRelease.name}`);

const oReleaseObject = {
name: oRelease.name,
url: oRelease.html_url,
version: oRelease.tag_name,
creationDate: oRelease.created_at,
releaseDate: oRelease.published_at || new Date().toISOString(),
description: oRelease.body,

author: oRelease.author.login,
authorAvatar: oRelease.author.avatar_url,
}

console.log(`Writing release notes to ${sFilePath}`);
fs.writeFileSync(sFilePath, JSON.stringify(oReleaseObject, null, "\t"));
console.log(`Done!`);
}

constructor(sAuthToken, sOwner, sRepo) {
this.owner = sOwner;
this.repo = sRepo;

this.octokit = new Octokit({
auth: sAuthToken,
});
}

async createReleaseNotes (sFilePath) {
const oRelease = await this.getReleaseInfos(this.owner, this.repo);
this.writeInfosToFile(oRelease, sFilePath);
}

async getReleaseInfos (sOwner, sRepo) {
const { data } = await this.octokit.request(`/repos/${sOwner}/${sRepo}/releases`);
return data;
}

writeInfosToFile (oRelease, sFilePath) {
console.log(`Found ${oRelease.length} release(s)`);

const mappedReleases = data.map((d) => ({
name: d.name,
url: d.html_url,
version: d.tag_name,
creationDate: d.created_at,
releaseDate: d.published_at || new Date().toISOString(),
description: d.body,
author: d.author.login,
authorAvatar: d.author.avatar_url,
}))

console.log(`Writing release notes to ${sFilePath}`);
fs.writeFileSync(sFilePath, JSON.stringify(mappedReleases));
console.log(`Done!`);
}
}

0 comments on commit 1c7e35e

Please sign in to comment.