Added support for the CI_TOKEN

This commit is contained in:
Evann JALLET
2025-01-06 14:30:52 +01:00
parent 176b6de578
commit 6fc034f590
4 changed files with 78 additions and 41 deletions

View File

@@ -14,5 +14,7 @@ inputs:
required: false
runs:
env:
CI_TOKEN: "${{ secrets.CI_TOKEN }}"
using: 'node20'
main: 'dist/app.js'

35
app.ts
View File

@@ -8,6 +8,8 @@ const IGNORED_BRANCHES: string[] = core.getInput('branchesToIgnore', { required:
const mainBranch: string = `origin/${ core.getInput('mainBranch', { required: false }) }`;
const { CI_TOKEN, GITHUB_SERVER_URL } = process.env;
enum Action {
Rebase = 0,
Reset = 1
@@ -206,7 +208,40 @@ const rebaseBranch = async ({
]);
}
const setupCIToken = async () => {
writeConsole("Overriding git repository auth with CI_TOKEN")
const remoteUrl = await runGitCommand([
"remote",
"get-url",
"origin"
]);
const httpLessUrl = remoteUrl.replace(/https?:\/\//, "");
const newUrl = `https://MilaBot:${ CI_TOKEN }@${ httpLessUrl }.git`;
await runGitCommand([
"remote",
"set-url",
"origin",
newUrl
]);
await runGitCommand([
"config",
"--local",
"--unset",
`http.https://${ GITHUB_SERVER_URL }/.extraheader`
]);
}
const setupAutoRebaseGit = async () => {
if (CI_TOKEN) {
await setupCIToken();
} else {
writeConsole("Couldn't find a CI_TOKEN. Using the gitea ghost.", LogLevel.WARNING);
}
await runGitCommand([
"config",
"user.email",

80
dist/app.js vendored

File diff suppressed because one or more lines are too long

2
dist/package.json vendored
View File

@@ -5,7 +5,7 @@
"main": "app.js",
"scripts": {
"prepare": "husky",
"build": "cp package.json dist/ && sed -i '' -E 's/\"type\": \".*$//' dist/package.json && esbuild --outdir=dist --bundle --platform=node --minify --format=cjs --allow-overwrite ./app.ts",
"build": "cp package.json dist/ && sed -i -E 's/\"type\": \".*$//' dist/package.json && esbuild --outdir=dist --bundle --platform=node --minify --format=cjs --allow-overwrite ./app.ts",
"dev": "tsx app.ts"
},