meli-cli/src/commands/upload/notify-git/set-commit-status.ts

42 lines
1.4 KiB
TypeScript

import { getRepoId } from '../ci/get-repo-id';
import { Github } from './github';
import { getCommitHash } from '../ci/get-commit-hash';
import { Logger } from '../../../commons/logger/logger';
import { Gitlab } from './gitlab';
import { Gitea } from './gitea';
import { UploadResponse } from '../upload-response';
const logger = new Logger('meli.cli:setCommitStatus');
export async function setCommitStatus(data: UploadResponse, release?: string): Promise<void> {
const commitHash = getCommitHash();
const repoId = getRepoId();
if (!repoId) {
logger[process.stdout.isTTY ? 'debug' : 'warn']('Repo id not detected, cannot set commit status');
return;
}
if (!commitHash) {
logger[process.stdout.isTTY ? 'debug' : 'warn']('Commit hash not detected, cannot set commit status');
return;
}
const context = 'meli';
const description = release ? `Release ${release} deployed to Meli` : 'Site deployed to Meli';
if (process.env.GITEA_TOKEN && process.env.GITEA_URL) {
logger.info('Setting Gitea commit status');
const gitea = new Gitea(process.env.GITEA_TOKEN, process.env.GITEA_URL);
await gitea.setCommitStatus(repoId, commitHash, {
context,
description,
state: data ? 'success' : 'failure',
url: data?.urls[0],
});
} else {
logger.debug('Gitea token/url not found, will not set commit status');
}
}