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

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",