Skip to content

Commit

Permalink
Initial commit of Github auto-merge action
Browse files Browse the repository at this point in the history
  • Loading branch information
alexwilson committed Feb 8, 2021
0 parents commit 9980046
Show file tree
Hide file tree
Showing 8 changed files with 9,350 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v12
12 changes: 12 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: 'Enable Github Automerge'
description: 'Enable Github auto-merge for specific pull-requests'
branding:
icon: 'git-merge'
color: 'green'
inputs:
github-token:
description: 'The GITHUB_TOKEN secret'
required: true
runs:
using: 'node12'
main: 'dist/index.js'
9,069 changes: 9,069 additions & 0 deletions dist/index.js

Large diffs are not rendered by default.

195 changes: 195 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "enable-github-automerge-action",
"version": "0.0.0-alpha.1",
"description": "",
"main": "dist/main.ts",
"scripts": {
"build": "ncc build src/main.ts",
"format": "prettier --write **/*.ts",
"format-check": "prettier --check **/*.ts"
},
"author": "Alex Wilson <[email protected]>",
"license": "ISC",
"devDependencies": {
"@types/node": "^14.14.25",
"@vercel/ncc": "^0.27.0",
"prettier": "^2.2.1",
"typescript": "^4.1.3"
},
"dependencies": {
"@actions/core": "^1.2.6",
"@actions/github": "^4.0.0"
}
}
36 changes: 36 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import * as core from "@actions/core";
import * as github from "@actions/github";

async function run() {
try {
const token = core.getInput("github-token", { required: true });
const client = github.getOctokit(token);

const { pull_request: pullRequest } = github.context.payload;
if (!pullRequest) {
throw new Error("Event payload missing `pull_request`");
}

core.debug(`Enabling auto-merge for pull-request #${pullRequest.number}`);
client.graphql(`
mutation {
enablePullRequestAutoMerge(input:{
pullRequestId: "${pullRequest.node_id}"
}) {
clientMutationId
pullRequest {
id
state
}
}
}
`);
core.debug(
`Successfully enabled auto-merge for pull-request #${pullRequest.number}`
);
} catch (error) {
core.setFailed(error.message);
}
}

run();
13 changes: 13 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"outDir": "./lib",
"rootDir": "./src",
"strict": true,
"noImplicitAny": false,
"esModuleInterop": true
},
"exclude": ["node_modules", "**/*.test.ts"]
}

0 comments on commit 9980046

Please sign in to comment.