Skip to content

Commit

Permalink
refactor: move Git check earlier
Browse files Browse the repository at this point in the history
  • Loading branch information
codebytere committed Aug 26, 2024
1 parent 624e027 commit ee739cf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ export const BACKPORT_REQUESTED_LABEL =

export const DEFAULT_BACKPORT_REVIEW_TEAM =
process.env.DEFAULT_BACKPORT_REVIEW_TEAM;

export const VALID_BACKPORT_CHECK_NAME =
process.env.BACKPORT_REQUESTED_LABEL || 'Valid Backport';
20 changes: 15 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ import {
labelExistsOnPR,
removeLabel,
} from './utils/label-utils';
import { CHECK_PREFIX, NO_BACKPORT_LABEL, SKIP_CHECK_LABEL } from './constants';
import {
CHECK_PREFIX,
NO_BACKPORT_LABEL,
SKIP_CHECK_LABEL,
VALID_BACKPORT_CHECK_NAME,
} from './constants';
import { getEnvVar } from './utils/env-util';
import { PRChange, PRStatus, BackportPurpose, CheckRunStatus } from './enums';
import { Label } from '@octokit/webhooks-types';
Expand All @@ -30,8 +35,9 @@ import {
import { register } from './utils/prom';
import { SimpleWebHookRepoContext, WebHookPR, WebHookPRContext } from './types';

// Built in fetch doesn't support global-agent...
// @ts-ignore
import { execSync } from 'child_process';

// @ts-ignore - builtin fetch doesn't support global-agent.
delete globalThis.fetch;

const probotHandler: ApplicationFunction = async (robot, { getRouter }) => {
Expand Down Expand Up @@ -140,6 +146,12 @@ const probotHandler: ApplicationFunction = async (robot, { getRouter }) => {
}
};

const gitExists = execSync('which git').toString().trim();
if (/git not found/.test(gitExists)) {
robot.log('Git not found - unable to proceed with backporting');
process.exit(1);
}

/**
* Checks that a PR done to `main` contains the required
* backport information, i.e.: at least a `no-backport` or
Expand All @@ -149,8 +161,6 @@ const probotHandler: ApplicationFunction = async (robot, { getRouter }) => {
* @returns
*/

const VALID_BACKPORT_CHECK_NAME = 'Valid Backport';

robot.on(
[
'pull_request.opened',
Expand Down

0 comments on commit ee739cf

Please sign in to comment.