mirror of
https://code.forgejo.org/actions/git-backporting.git
synced 2025-05-29 08:54:30 -04:00
refactor: updated logging messages (#65)
This commit is contained in:
parent
e29dae5073
commit
a8db0755a8
18 changed files with 88 additions and 85 deletions
|
@ -60,7 +60,7 @@ export default class GitCLIService {
|
|||
* @param branch branch which should be cloned
|
||||
*/
|
||||
async clone(from: string, to: string, branch: string): Promise<void> {
|
||||
this.logger.info(`Cloning repository ${from} to ${to}.`);
|
||||
this.logger.info(`Cloning repository ${from} to ${to}`);
|
||||
if (!fs.existsSync(to)) {
|
||||
await simpleGit().clone(this.remoteWithAuth(from), to, ["--quiet", "--shallow-submodules", "--no-tags", "--branch", branch]);
|
||||
} else {
|
||||
|
@ -74,7 +74,7 @@ export default class GitCLIService {
|
|||
* @param newBranch new branch name
|
||||
*/
|
||||
async createLocalBranch(cwd: string, newBranch: string): Promise<void> {
|
||||
this.logger.info(`Creating branch ${newBranch}.`);
|
||||
this.logger.info(`Creating branch ${newBranch}`);
|
||||
await this.git(cwd).checkoutLocalBranch(newBranch);
|
||||
}
|
||||
|
||||
|
@ -85,7 +85,7 @@ export default class GitCLIService {
|
|||
* @param remoteName [optional] name of the remote, by default 'fork' is used
|
||||
*/
|
||||
async addRemote(cwd: string, remote: string, remoteName = "fork"): Promise<void> {
|
||||
this.logger.info(`Adding new remote ${remote}.`);
|
||||
this.logger.info(`Adding new remote ${remote}`);
|
||||
await this.git(cwd).addRemote(remoteName, this.remoteWithAuth(remote));
|
||||
}
|
||||
|
||||
|
@ -96,7 +96,7 @@ export default class GitCLIService {
|
|||
* @param remote [optional] the remote to fetch, by default origin
|
||||
*/
|
||||
async fetch(cwd: string, branch: string, remote = "origin"): Promise<void> {
|
||||
this.logger.info(`Fetching ${remote} ${branch}.`);
|
||||
this.logger.info(`Fetching ${remote} ${branch}`);
|
||||
await this.git(cwd).fetch(remote, branch, ["--quiet"]);
|
||||
}
|
||||
|
||||
|
@ -106,7 +106,7 @@ export default class GitCLIService {
|
|||
* @param sha commit sha
|
||||
*/
|
||||
async cherryPick(cwd: string, sha: string, strategy = "recursive", strategyOption = "theirs"): Promise<void> {
|
||||
this.logger.info(`Cherry picking ${sha}.`);
|
||||
this.logger.info(`Cherry picking ${sha}`);
|
||||
|
||||
const options = ["cherry-pick", "-m", "1", `--strategy=${strategy}`, `--strategy-option=${strategyOption}`, sha];
|
||||
try {
|
||||
|
@ -128,7 +128,7 @@ export default class GitCLIService {
|
|||
* @param remote [optional] remote to which the branch should be pushed to, by default 'origin'
|
||||
*/
|
||||
async push(cwd: string, branch: string, remote = "origin", force = false): Promise<void> {
|
||||
this.logger.info(`Pushing ${branch} to ${remote}.`);
|
||||
this.logger.info(`Pushing ${branch} to ${remote}`);
|
||||
|
||||
const options = ["--quiet"];
|
||||
if (force) {
|
||||
|
|
|
@ -13,9 +13,10 @@ export default class GitClientFactory {
|
|||
private static logger: LoggerService = LoggerServiceFactory.getLogger();
|
||||
private static instance?: GitClient;
|
||||
|
||||
// this method assumes there already exists a singleton client instance, otherwise it will fail
|
||||
public static getClient(): GitClient {
|
||||
if (!GitClientFactory.instance) {
|
||||
throw new Error("You must call `getOrCreate` method first!");
|
||||
throw new Error("You must call `getOrCreate` method first");
|
||||
}
|
||||
|
||||
return GitClientFactory.instance;
|
||||
|
@ -29,7 +30,7 @@ export default class GitClientFactory {
|
|||
public static getOrCreate(type: GitClientType, authToken: string | undefined, apiUrl: string): GitClient {
|
||||
|
||||
if (GitClientFactory.instance) {
|
||||
GitClientFactory.logger.warn("Git service already initialized!");
|
||||
GitClientFactory.logger.warn("Git service already initialized");
|
||||
return GitClientFactory.instance;
|
||||
}
|
||||
|
||||
|
@ -49,8 +50,9 @@ export default class GitClientFactory {
|
|||
return GitClientFactory.instance;
|
||||
}
|
||||
|
||||
// this is used for testing purposes
|
||||
public static reset(): void {
|
||||
GitClientFactory.logger.warn("Resetting git service!");
|
||||
GitClientFactory.logger.warn("Resetting git service");
|
||||
GitClientFactory.instance = undefined;
|
||||
}
|
||||
}
|
|
@ -32,7 +32,7 @@ export default class GitHubClient implements GitClient {
|
|||
}
|
||||
|
||||
async getPullRequest(owner: string, repo: string, prNumber: number, squash = true): Promise<GitPullRequest> {
|
||||
this.logger.info(`Getting pull request ${owner}/${repo}/${prNumber}.`);
|
||||
this.logger.debug(`Fetching pull request ${owner}/${repo}/${prNumber}`);
|
||||
const { data } = await this.octokit.rest.pulls.get({
|
||||
owner: owner,
|
||||
repo: repo,
|
||||
|
@ -66,7 +66,7 @@ export default class GitHubClient implements GitClient {
|
|||
// WRITE
|
||||
|
||||
async createPullRequest(backport: BackportPullRequest): Promise<string> {
|
||||
this.logger.info(`Creating pull request ${backport.head} -> ${backport.base}.`);
|
||||
this.logger.info(`Creating pull request ${backport.head} -> ${backport.base}`);
|
||||
this.logger.info(`${JSON.stringify(backport, null, 2)}`);
|
||||
|
||||
const { data } = await this.octokit.pulls.create({
|
||||
|
|
|
@ -12,7 +12,6 @@ export default class OctokitFactory {
|
|||
|
||||
public static getOctokit(token: string | undefined, apiUrl: string): Octokit {
|
||||
if (!OctokitFactory.octokit) {
|
||||
OctokitFactory.logger.info("Creating octokit instance.");
|
||||
OctokitFactory.octokit = new Octokit({
|
||||
auth: token,
|
||||
userAgent: "kiegroup/git-backporting",
|
||||
|
|
|
@ -69,7 +69,7 @@ export default class GitLabClient implements GitClient {
|
|||
// WRITE
|
||||
|
||||
async createPullRequest(backport: BackportPullRequest): Promise<string> {
|
||||
this.logger.info(`Creating pull request ${backport.head} -> ${backport.base}.`);
|
||||
this.logger.info(`Creating pull request ${backport.head} -> ${backport.base}`);
|
||||
this.logger.info(`${JSON.stringify(backport, null, 2)}`);
|
||||
|
||||
const projectId = this.getProjectId(backport.owner, backport.repo);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue