Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ensure git found on trop runner #304

Merged
merged 3 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
}
11 changes: 3 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,7 @@ import {
updateBackportValidityCheck,
} from './utils/checks-util';
import { register } from './utils/prom';
import {
SimpleWebHookRepoContext,
WebHookIssueContext,
WebHookPR,
WebHookPRContext,
} from './types';
import { SimpleWebHookRepoContext, WebHookPR, WebHookPRContext } from './types';

// Built in fetch doesn't support global-agent...
// @ts-ignore
Expand Down Expand Up @@ -423,7 +418,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 +466,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();
codebytere marked this conversation as resolved.
Show resolved Hide resolved
codebytere marked this conversation as resolved.
Show resolved Hide resolved
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