Skip to content

Commit

Permalink
fix: ensure git found on trop runner
Browse files Browse the repository at this point in the history
  • Loading branch information
codebytere committed Aug 23, 2024
1 parent c8c9cf4 commit ff7b372
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 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
11 changes: 5 additions & 6 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@
"required": true
}
},
"formation": {
},
"addons": [

],
"formation": {},
"addons": [],
"buildpacks": [
{
"url": "heroku/nodejs"
}, {
"url": "heroku-community/apt"
}
],
"stack": "heroku-22"
"stack": "heroku-24"
}
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ const probotHandler: ApplicationFunction = async (robot, { getRouter }) => {
'pull_request.unlabeled',
'pull_request.synchronize',
],
async (context) => {
async (context: WebHookPRContext) => {
const pr = context.payload.pull_request;

if (pr.base.ref !== pr.base.repo.default_branch) {
Expand Down Expand Up @@ -423,7 +423,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 +471,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 ff7b372

Please sign in to comment.