Skip to content

Commit

Permalink
fix: ensure git found on trop runner (#304)
Browse files Browse the repository at this point in the history
  • Loading branch information
codebytere authored Sep 4, 2024
1 parent c8c9cf4 commit 439152f
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 21 deletions.
2 changes: 2 additions & 0 deletions Aptfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Heroku-24 stack doesn't include git by default.
git-all
12 changes: 6 additions & 6 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
"required": true
}
},
"formation": {
},
"addons": [

],
"formation": {},
"addons": [],
"buildpacks": [
{
"url": "heroku-community/apt"
},
{
"url": "heroku/nodejs"
}
],
"stack": "heroku-22"
"stack": "heroku-24"
}
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';
33 changes: 19 additions & 14 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 @@ -28,15 +33,11 @@ import {
updateBackportValidityCheck,
} from './utils/checks-util';
import { register } from './utils/prom';
import {
SimpleWebHookRepoContext,
WebHookIssueContext,
WebHookPR,
WebHookPRContext,
} from './types';

// Built in fetch doesn't support global-agent...
// @ts-ignore
import { SimpleWebHookRepoContext, WebHookPR, WebHookPRContext } from './types';

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 @@ -145,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 @@ -154,8 +161,6 @@ const probotHandler: ApplicationFunction = async (robot, { getRouter }) => {
* @returns
*/

const VALID_BACKPORT_CHECK_NAME = 'Valid Backport';

robot.on(
[
'pull_request.opened',
Expand Down Expand Up @@ -423,7 +428,7 @@ const probotHandler: ApplicationFunction = async (robot, { getRouter }) => {
);

// Backport pull requests to labeled targets when PR is merged.
robot.on('pull_request.closed', async (context: WebHookPRContext) => {
robot.on('pull_request.closed', async (context) => {
const { pull_request: pr } = context.payload;

const oldPRNumbers = getPRNumbersFromPRBody(pr, true);
Expand Down Expand Up @@ -471,7 +476,7 @@ const probotHandler: ApplicationFunction = async (robot, { getRouter }) => {
const TROP_COMMAND_PREFIX = '/trop ';

// Manually trigger backporting process on trigger comment phrase.
robot.on('issue_comment.created', async (context: WebHookIssueContext) => {
robot.on('issue_comment.created', async (context) => {
const { issue, comment } = context.payload;

const isPullRequest = (i: { number: number; html_url: string }) =>
Expand Down
14 changes: 13 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import fetch from 'node-fetch';
import * as fs from 'fs-extra';
import { execSync } from 'child_process';
import Queue from 'queue';
import simpleGit from 'simple-git';

Expand Down Expand Up @@ -29,7 +30,7 @@ import {
WebHookPR,
WebHookRepoContext,
} from './types';
import { Context, Probot } from 'probot';
import { Probot } from 'probot';

const { parse: parseDiff } = require('what-the-diff');

Expand Down Expand Up @@ -475,6 +476,17 @@ export const backportImpl = async (
}
}

const gitExists = execSync('which git').toString().trim();
if (/git not found/.test(gitExists)) {
await context.octokit.issues.createComment(
context.repo({
body: `Git not found - unable to proceed with backporting to ${targetBranch}`,
issue_number: pr.number,
}),
);
return;
}

const base = pr.base;
const slug = `${base.repo.owner.login}/${base.repo.name}`;
const bp = `backport from PR #${pr.number} to "${targetBranch}"`;
Expand Down

0 comments on commit 439152f

Please sign in to comment.