Skip to content

Commit

Permalink
chore: adapt strategy to pick the commit from the user defined one
Browse files Browse the repository at this point in the history
  • Loading branch information
gregberge committed Aug 22, 2024
1 parent 87442ad commit 062d47d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions apps/backend/src/build/strategy/strategies/ci/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ async function getBaseScreenshotBucket(build: Build) {
ctx,
base,
head,
build,
});

if (!mergeBaseCommitSha) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { invariant } from "@argos/util/invariant";

import { GithubRepository, Project } from "@/database/models/index.js";
import {
GithubInstallation,
GithubRepository,
Project,
} from "@/database/models/index.js";
import { checkErrorStatus, getInstallationOctokit } from "@/github/index.js";
import { UnretryableError } from "@/job-core/index.js";

Expand All @@ -12,6 +16,7 @@ export const GithubStrategy: MergeBaseStrategy<{
octokit: Octokit;
owner: string;
repo: string;
installation: GithubInstallation;
}> = {
detect: (project: Project) => Boolean(project.githubRepositoryId),
getContext: async (project: Project) => {
Expand Down Expand Up @@ -52,6 +57,11 @@ export const GithubStrategy: MergeBaseStrategy<{
},

getMergeBaseCommitSha: async (args) => {
// If the app is light, then we rely on the reference commit provided by the user in CLI.
if (args.ctx.installation.app === "light") {
return args.build.referenceCommit;
}

try {
const { data } =
await args.ctx.octokit.rest.repos.compareCommitsWithBasehead({
Expand Down
3 changes: 2 additions & 1 deletion apps/backend/src/build/strategy/strategies/ci/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Project } from "@/database/models/index.js";
import type { Build, Project } from "@/database/models/index.js";

export type MergeBaseStrategy<TCtx> = {
detect: (project: Project) => Promise<boolean> | boolean;
Expand All @@ -8,6 +8,7 @@ export type MergeBaseStrategy<TCtx> = {
ctx: TCtx;
base: string;
head: string;
build: Build;
}) => Promise<string | null>;
listParentCommitShas: (args: {
project: Project;
Expand Down

0 comments on commit 062d47d

Please sign in to comment.