Skip to content

Commit

Permalink
Use git material for sha lookup (#555)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattgauntseo-sentry authored Jul 26, 2023
1 parent 6b6a0ec commit 3124360
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/brain/gocdSlackFeeds/deployFeed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { GoCDModification, GoCDPipeline, GoCDResponse } from '@/types';
import { getLastGetSentryGoCDDeploy } from '@/utils/db/getLatestDeploy';
import { getSlackMessage } from '@/utils/db/getSlackMessage';
import { saveSlackMessage } from '@/utils/db/saveSlackMessage';
import { firstMaterialSHA, getProgressColor } from '@/utils/gocdHelpers';
import { firstGitMaterialSHA, getProgressColor } from '@/utils/gocdHelpers';

export class DeployFeed {
private feedName: string;
Expand Down Expand Up @@ -124,7 +124,7 @@ export class DeployFeed {
return;
}

const latestSHA = firstMaterialSHA(latestDeploy);
const latestSHA = firstGitMaterialSHA(latestDeploy);
if (!latestSHA) {
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/brain/notifyOnGoCDStageEvent/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { queueCommitsForDeploy } from '@/utils/db/queueCommitsForDeploy';
import {
ALL_MESSAGE_SUFFIX,
FINAL_STAGE_NAMES,
firstMaterialSHA,
firstGitMaterialSHA,
getProgressColor,
getProgressSuffix,
} from '@/utils/gocdHelpers';
Expand Down Expand Up @@ -279,7 +279,7 @@ export async function handler(resBody: GoCDResponse) {
const commits = await getCommitsInDeployment(
GETSENTRY_ORG,
sha,
firstMaterialSHA(latestDeploy)
firstGitMaterialSHA(latestDeploy)
);
const relevantCommitShas: string[] = await filterCommits(pipeline, commits);

Expand Down
4 changes: 2 additions & 2 deletions src/brain/pleaseDeployNotifier/actionViewUndeployedCommits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
GOCD_SENTRYIO_BE_PIPELINE_GROUP,
GOCD_SENTRYIO_BE_PIPELINE_NAME,
} from '@/config';
import { firstMaterialSHA } from '@/utils/gocdHelpers';
import { firstGitMaterialSHA } from '@/utils/gocdHelpers';
import { getBlocksForCommit } from '@api/getBlocksForCommit';
import { getRelevantCommit } from '@api/github/getRelevantCommit';
import { getLastGetSentryGoCDDeploy } from '@utils/db/getLatestDeploy';
Expand Down Expand Up @@ -66,7 +66,7 @@ export async function actionViewUndeployedCommits({
return;
}

const base = firstMaterialSHA(lastDeploy);
const base = firstGitMaterialSHA(lastDeploy);
if (!base) {
// Failed to get base sha
return;
Expand Down
38 changes: 31 additions & 7 deletions src/utils/gocdHelpers.test.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,57 @@
import { firstMaterialSHA } from '@/utils/gocdHelpers';
import { firstGitMaterialSHA } from '@/utils/gocdHelpers';

describe('firstMaterialSHA', () => {
describe('firstGitMaterialSHA', () => {
it('return nothing for no deploy', async function () {
const got = firstMaterialSHA(null);
const got = firstGitMaterialSHA(null);
expect(got).toEqual(null);
});

it('return nothing no build materials', async function () {
const got = firstMaterialSHA({
const got = firstGitMaterialSHA({
pipeline_build_cause: [],
});
expect(got).toEqual(null);
});

it('return nothing no modifications', async function () {
const got = firstMaterialSHA({
it('return nothing for no modifications', async function () {
const got = firstGitMaterialSHA({
pipeline_build_cause: [
{
material: {
type: 'git',
},
modifications: [],
},
],
});
expect(got).toEqual(null);
});

it('return null for non-git material sha', async function () {
const got = firstGitMaterialSHA({
pipeline_build_cause: [
{
material: {
type: 'other',
},
modifications: [
{
revision: 'example-pipeline/1/example-stage',
},
],
},
],
});
expect(got).toEqual(null);
});

it('return first material sha', async function () {
const got = firstMaterialSHA({
const got = firstGitMaterialSHA({
pipeline_build_cause: [
{
material: {
type: 'git',
},
modifications: [
{
revision: 'abc123',
Expand Down
15 changes: 10 additions & 5 deletions src/utils/gocdHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export function getProgressColor(pipeline: GoCDPipeline) {
}
}

export function firstMaterialSHA(
export function firstGitMaterialSHA(
deploy: DBGoCDDeployment | undefined
): string | null {
if (!deploy) {
Expand All @@ -87,9 +87,14 @@ export function firstMaterialSHA(
if (deploy.pipeline_build_cause.length == 0) {
return null;
}
const bc = deploy.pipeline_build_cause[0];
if (bc.modifications.length == 0) {
return null;
for (const bc of deploy.pipeline_build_cause) {
if (!bc.material || bc.material.type != 'git') {
continue;
}
if (bc.modifications.length == 0) {
continue;
}
return bc.modifications[0].revision;
}
return bc.modifications[0].revision;
return null;
}

0 comments on commit 3124360

Please sign in to comment.