-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathrename_release.js
57 lines (46 loc) · 1.3 KB
/
rename_release.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { Octokit } from '@octokit/rest';
import fs from 'fs';
import { exit } from 'process';
// Initialize Octokit with your token
const octokit = new Octokit({ auth: process.env.GITHUB_TOKEN });
// Your repo information
const owner = 'swiiny';
const repo = 'create-nextjs-dapp';
// Read the version-names.rc file
const versionNames = JSON.parse(fs.readFileSync('versions.json'));
async function renameRelease() {
try {
// Fetch the latest release
const { data: latestRelease } = await octokit.rest.repos.getLatestRelease({
owner,
repo
});
// Get the version number (assuming tag is the version)
const version = latestRelease.tag_name;
// Determine the name from the version
let newName = '';
for (const [versionPattern, name] of Object.entries(versionNames)) {
if (new RegExp(versionPattern.replace('x', '\\d+')).test(version)) {
newName = name;
break;
}
}
if (!newName) {
console.log(`No matching version name for ${version}`);
exit(1);
}
// Update the release name
await octokit.rest.repos.updateRelease({
owner,
repo,
release_id: latestRelease.id,
name: `${newName} (${version})`
});
console.log(`Release renamed to ${newName}`);
exit(0);
} catch (error) {
console.error(`Error renaming release: ${error}`);
exit(1);
}
}
renameRelease();