Fix/script changelog creation (#496)
* [Tooling] Select git commit author correctly Caused the credit for a commit without a pr id to show as "@[object Object]" * [Tooling] Fix typo in file name * [Tooling] Use total commit count from webUI repos master branch
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
"build-md5": "find build -type f | sort | xargs md5sum | awk '{ print $1 }' | tr -d '\n' | md5sum| awk '{ print $1 }' > buildZip/md5sum ",
|
||||
"build-zip": "cd build && rev=$(git rev-list HEAD --count) && echo r$rev > revision && zip -9 -r ../buildZip/Tachidesk-WebUI-r$rev *",
|
||||
"lint": "eslint src --ext .ts,.tsx,.js,.jsx",
|
||||
"createChangelog": "ts-node tools/scripts/createReleaseChanglog.ts",
|
||||
"createChangelog": "ts-node tools/scripts/createReleaseChangelog.ts",
|
||||
"updateDeps": "yarn upgrade && yarn syncyarnlock -s -k && yarn && git add package.json yarn.lock && git commit -m \"Update dependencies\" && echo Updated non breaking dependencies. Check potential breaking changes below... && yarn outdated",
|
||||
"gql:codegen-base": "graphql-codegen --config gql_codegen.ts",
|
||||
"gql:codegen-formatter": "ts-node tools/scripts/codegenFormatter.ts",
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
import { execSync } from 'child_process';
|
||||
import yargs from 'yargs';
|
||||
import githubToken from './github_token.json';
|
||||
|
||||
@@ -15,7 +14,9 @@ type GithubCommit = {
|
||||
html_url: string;
|
||||
commit: {
|
||||
message: string;
|
||||
author: string;
|
||||
author: {
|
||||
name: string;
|
||||
};
|
||||
};
|
||||
author: { login: string } | null;
|
||||
};
|
||||
@@ -39,6 +40,29 @@ const { sha } = yargs
|
||||
})
|
||||
.parseSync();
|
||||
|
||||
const getHeaderWithAuth = () => ({
|
||||
headers: {
|
||||
// token is optional, might be needed in case of getting rate-limited - to provide a token create a "github_token.json" (see "github_token.template.json") and add your token in there
|
||||
Authorization: githubToken.token ? `token ${githubToken.token}` : '',
|
||||
},
|
||||
});
|
||||
|
||||
const fetchTotalCommitCount = async (owner: string, repo: string, branch: string = 'master') => {
|
||||
const response = await fetch(
|
||||
`https://api.github.com/repos/${owner}/${repo}/commits?sha=${branch}&per_page=1&page=1`,
|
||||
getHeaderWithAuth(),
|
||||
);
|
||||
|
||||
const linkHeader = response.headers.get('Link');
|
||||
const pageCountMatch = linkHeader?.match(/page=(\d+)>; rel="last"/);
|
||||
|
||||
if (!pageCountMatch) {
|
||||
throw new Error('Page count not found in Link header');
|
||||
}
|
||||
|
||||
return parseInt(pageCountMatch[1], 10);
|
||||
};
|
||||
|
||||
/**
|
||||
* Fetches and returns all commits after the provided commit hash
|
||||
*/
|
||||
@@ -49,12 +73,7 @@ const fetchCommits = async (
|
||||
page: number = 1,
|
||||
): Promise<GithubCommit[]> => {
|
||||
const commitList = (await (
|
||||
await fetch(`https://api.github.com/repos/${owner}/${repo}/commits?page=${page}`, {
|
||||
headers: {
|
||||
// token is optional, might be needed in case of getting rate-limited - to provide a token create a "github_token.json" (see "github_token.template.json") and add your token in there
|
||||
Authorization: githubToken.token ? `token ${githubToken.token}` : '',
|
||||
},
|
||||
})
|
||||
await fetch(`https://api.github.com/repos/${owner}/${repo}/commits?page=${page}`, getHeaderWithAuth())
|
||||
).json()) as GithubCommit[];
|
||||
const indexOfOldestCommitToLoad = commitList.findIndex((commit) => commit.sha === loadUntilSha);
|
||||
|
||||
@@ -90,7 +109,7 @@ const createChangelog = async (prevReleaseLastCommitSha: string) => {
|
||||
const owner = 'Suwayomi';
|
||||
const repo = 'Tachidesk-WebUI';
|
||||
|
||||
const numberOfCommits = Number(execSync('git rev-list origin/master --count').toString());
|
||||
const numberOfCommits = await fetchTotalCommitCount(owner, repo);
|
||||
const githubCommits = await fetchCommits(owner, repo, prevReleaseLastCommitSha);
|
||||
|
||||
const commits: Commit[] = githubCommits.map((githubCommit, index) => ({
|
||||
@@ -98,7 +117,7 @@ const createChangelog = async (prevReleaseLastCommitSha: string) => {
|
||||
revision: numberOfCommits - index,
|
||||
url: githubCommit.html_url,
|
||||
githubUser: githubCommit.author?.login,
|
||||
author: githubCommit.commit.author,
|
||||
author: githubCommit.commit.author.name,
|
||||
title: githubCommit.commit.message.split('\n')[0],
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user