mirror of
https://code.forgejo.org/actions/git-backporting.git
synced 2025-05-18 11:39:12 -04:00
fix(gh-96): fix git token parsing (#98)
This commit is contained in:
parent
2c5c54654d
commit
c57fca6bd6
14 changed files with 324 additions and 342 deletions
|
@ -8,7 +8,7 @@ import GitClientFactory from "@bp/service/git/git-client-factory";
|
|||
import { BackportPullRequest, GitClientType, GitPullRequest } from "@bp/service/git/git.types";
|
||||
import LoggerService from "@bp/service/logger/logger-service";
|
||||
import LoggerServiceFactory from "@bp/service/logger/logger-service-factory";
|
||||
import { inferGitClient, inferGitApiUrl } from "@bp/service/git/git-util";
|
||||
import { inferGitClient, inferGitApiUrl, getGitTokenFromEnv } from "@bp/service/git/git-util";
|
||||
|
||||
interface Git {
|
||||
gitClientType: GitClientType;
|
||||
|
@ -63,10 +63,12 @@ export default class Runner {
|
|||
const gitClientType: GitClientType = inferGitClient(args.pullRequest);
|
||||
// the api version is ignored in case of github
|
||||
const apiUrl = inferGitApiUrl(args.pullRequest, gitClientType === GitClientType.CODEBERG ? "v1" : undefined);
|
||||
const gitApi: GitClient = GitClientFactory.getOrCreate(gitClientType, args.auth, apiUrl);
|
||||
const token = this.fetchToken(args, gitClientType);
|
||||
const gitApi: GitClient = GitClientFactory.getOrCreate(gitClientType, token, apiUrl);
|
||||
|
||||
// 3. parse configs
|
||||
this.logger.debug("Parsing configs..");
|
||||
args.auth = token; // override auth
|
||||
const configs: Configs = await new PullRequestConfigsParser().parseAndValidate(args);
|
||||
const backportPRs: BackportPullRequest[] = configs.backportPullRequests;
|
||||
|
||||
|
@ -94,6 +96,27 @@ export default class Runner {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the GIT token from the provided Args obj, if not empty, otherwise fallback
|
||||
* to the environment variables.
|
||||
* @param args input arguments
|
||||
* @param gitType git client type
|
||||
* @returns the provided or fetched token, or undefined if not set anywhere
|
||||
*/
|
||||
fetchToken(args: Args, gitType: GitClientType): string | undefined {
|
||||
let token = args.auth;
|
||||
if (token === undefined) {
|
||||
// try to fetch the auth from env variable
|
||||
this.logger.info("Auth argument not provided, checking available tokens from env..");
|
||||
token = getGitTokenFromEnv(gitType);
|
||||
if (!token) {
|
||||
this.logger.info("Git token not found in the environment");
|
||||
}
|
||||
}
|
||||
|
||||
return token;
|
||||
}
|
||||
|
||||
async executeBackport(configs: Configs, backportPR: BackportPullRequest, git: Git): Promise<void> {
|
||||
this.logger.setContext(backportPR.base);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue