Skip to content

Commit

Permalink
changed merge type
Browse files Browse the repository at this point in the history
  • Loading branch information
Bullrich committed Sep 26, 2023
1 parent 7f22891 commit 218a910
Show file tree
Hide file tree
Showing 5 changed files with 454 additions and 491 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
"dependencies": {
"@actions/core": "^1.10.1",
"@actions/github": "^5.1.1",
"@octokit/graphql": "^7.0.2",
"@octokit/webhooks-types": "^7.3.1"
"@octokit/graphql": "^7.0.2"
},
"devDependencies": {
"@eng-automation/js-style": "^2.3.0",
"@octokit/graphql-schema": "^14.32.1",
"@octokit/webhooks-types": "^7.3.1",
"@types/jest": "^29.5.5",
"@vercel/ncc": "^0.38.0",
"jest": "^29.7.0",
Expand Down
4 changes: 3 additions & 1 deletion src/github/merger.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { graphql } from "@octokit/graphql";
import { ActionLogger } from "./types";
import { PullRequestMergeMethod } from "@octokit/graphql-schema";


// https://docs.github.com/en/graphql/reference/mutations#enablepullrequestautomerge
export const ENABLE_AUTO_MERGE = `
Expand All @@ -20,7 +22,7 @@ mutation($prId: ID!) {
export type MergeMethod = "SQUASH" | "MERGE" | "REBASE";

export class Merger {
constructor(private readonly nodeId: string, private readonly gql: typeof graphql, private readonly logger: ActionLogger, private readonly mergeMethod: MergeMethod) {
constructor(private readonly nodeId: string, private readonly gql: typeof graphql, private readonly logger: ActionLogger, private readonly mergeMethod: PullRequestMergeMethod) {

}

Expand Down
8 changes: 5 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import { getInput, setFailed, setOutput } from "@actions/core";
import { context, getOctokit } from "@actions/github";
import { Context } from "@actions/github/lib/context";
import { graphql } from "@octokit/graphql/dist-types/types";
import { PullRequestMergeMethod } from "@octokit/graphql-schema";
import { Issue, IssueComment } from "@octokit/webhooks-types";

import { Bot } from "./bot";
import { CommentsApi } from "./github/comments";
import { MergeMethod, Merger } from "./github/merger";
import { Merger } from "./github/merger";
import { generateCoreLogger } from "./util";

const getRepo = (ctx: Context) => {
Expand Down Expand Up @@ -37,14 +38,15 @@ if (context.eventName !== "issue_comment") {
throw new Error("Comment happened on an issue, not a PR");
}

const getMergeMethod = (): MergeMethod => {
const getMergeMethod = (): PullRequestMergeMethod => {
const method = (getInput("MERGE_METHOD", { required: false }) ??
"SQUASH") as MergeMethod;
"SQUASH") as PullRequestMergeMethod;
if (method !== "SQUASH" && method !== "MERGE" && method !== "REBASE") {
throw new Error(
"MERGE_METHOD must be either 'SQUASH', 'MERGE' or 'REBASE'",
);
}
logger.info(`Merge type is '${method}'`);

return method;
};
Expand Down
2 changes: 1 addition & 1 deletion src/test/queries.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { validate } from "@octokit/graphql-schema";
import { validate, PullRequestMergeMethod } from "@octokit/graphql-schema";

import { ENABLE_AUTO_MERGE, DISABLE_AUTO_MERGE } from "../github/merger";

Expand Down
Loading

0 comments on commit 218a910

Please sign in to comment.