-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b692116
commit 65f5854
Showing
369 changed files
with
192,158 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.idea | ||
yarn-error.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2021 Remato | ||
Copyright (c) 2021 Remato | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Open pull request action | ||
|
||
|
||
The action tries to open PR and then checks if the PR is mergeable. If mergeable then action returns PR id, if not then process exits with error code 1 to prevent later execution. | ||
Now maximum time to wait for PR state is 3 sec. | ||
|
||
```yaml | ||
name: Open pull request and echo its number | ||
on: | ||
push: | ||
branches: ["change_this"] | ||
jobs: | ||
example: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Open PR | ||
id: open_pr | ||
uses: rematocorp/open-pull-request-action@v1 | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
from-branch: change_this | ||
to-branch: change_this | ||
repository-owner: change_this | ||
repository: change_this | ||
|
||
- name: Echo mergeable PR number | ||
run: echo "${{ join(steps.open_pr.outputs.*, '') }}" | ||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
author: Remato | ||
name: open-pull-request | ||
description: GitHub Action to open pull request and return it's id if request is mergeable, otherwise throw error to stop the flow | ||
branding: | ||
color: yellow | ||
icon: anchor | ||
inputs: | ||
github-token: | ||
description: Github token, https://docs.github.com/en/actions/reference/authentication-in-a-workflow | ||
required: true | ||
from-branch: | ||
description: head branch | ||
required: true | ||
to-branch: | ||
description: base branch | ||
required: true | ||
repository-owner: | ||
required: true | ||
repository: | ||
required: true | ||
|
||
runs: | ||
using: node12 | ||
main: 'dist/index.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
exports.__esModule = true; | ||
var core = require("@actions/core"); | ||
var Octokit = require('@octokit/core').Octokit; | ||
var octokit; | ||
var retryCount = 0; | ||
var maxAttempts = 3; // https://youtu.be/-IOMNUayJjI | ||
function run() { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var githubToken, head, base, owner, repo, response, pull_number; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
githubToken = core.getInput('github-token', { required: true }); | ||
head = core.getInput('from-branch', { required: true }); | ||
base = core.getInput('to-branch', { required: true }); | ||
owner = core.getInput('repository-owner', { required: true }); | ||
repo = core.getInput('repository', { required: true }); | ||
octokit = new Octokit({ auth: githubToken }); | ||
return [4 /*yield*/, octokit.request('POST /repos/{owner}/{repo}/pulls', { | ||
owner: owner, | ||
repo: repo, | ||
head: head, | ||
base: base, | ||
title: "Auto merge ".concat(head, " to ").concat(base) | ||
})]; | ||
case 1: | ||
response = _a.sent(); | ||
pull_number = response.data.number; | ||
core.info('PR created'); | ||
return [4 /*yield*/, returnPullRequestNumber({ | ||
repo: repo, | ||
owner: owner, | ||
pull_number: pull_number | ||
})]; | ||
case 2: | ||
_a.sent(); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
} | ||
function returnPullRequestNumber(requestData) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var pull_request; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, octokit.request("GET /repos/{owner}/{repo}/pulls/{pull_number}", requestData)]; | ||
case 1: | ||
pull_request = _a.sent(); | ||
if (!(pull_request.data.mergeable_state == 'unknown')) return [3 /*break*/, 3]; | ||
if (retryCount >= maxAttempts) { | ||
core.error("Get pr status max attempts limit exceeded, payload: ".concat(JSON.stringify(requestData))); | ||
process.exit(1); | ||
} | ||
retryCount++; | ||
return [4 /*yield*/, delay(1000)]; | ||
case 2: | ||
_a.sent(); | ||
return [2 /*return*/, returnPullRequestNumber(requestData)]; | ||
case 3: | ||
if (pull_request.data.mergeable) { | ||
core.setOutput('pull_number', requestData.pull_number); | ||
} | ||
else { | ||
core.error("Pull request #".concat(requestData.pull_number, " is not mergeable")); | ||
process.exit(1); | ||
} | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
} | ||
function delay(ms) { | ||
return new Promise(function (resolve) { return setTimeout(resolve, ms); }); | ||
} | ||
run().then(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import * as core from '@actions/core' | ||
const { Octokit } = require('@octokit/core') | ||
|
||
let octokit | ||
let retryCount = 0 | ||
const maxAttempts = 3 // https://youtu.be/-IOMNUayJjI | ||
|
||
async function run(): Promise<void> { | ||
const githubToken = core.getInput('github-token', { required: true }) | ||
const head = core.getInput('from-branch', { required: true }) | ||
const base = core.getInput('to-branch', { required: true }) | ||
const owner = core.getInput('repository-owner', { required: true }) | ||
const repo = core.getInput('repository', { required: true }) | ||
|
||
octokit = new Octokit({ auth: githubToken }) | ||
|
||
const response = await octokit.request('POST /repos/{owner}/{repo}/pulls', { | ||
owner, | ||
repo, | ||
head, | ||
base, | ||
title: `Auto merge ${head} to ${base}`, | ||
}) | ||
|
||
const pull_number = response.data.number | ||
|
||
core.info('PR created') | ||
|
||
await returnPullRequestNumber({ | ||
repo, | ||
owner, | ||
pull_number, | ||
}) | ||
} | ||
|
||
async function returnPullRequestNumber(requestData: { | ||
owner: string | ||
repo: string | ||
pull_number: string | ||
}): Promise<void> { | ||
const pull_request = await octokit.request(`GET /repos/{owner}/{repo}/pulls/{pull_number}`, requestData) | ||
|
||
if (pull_request.data.mergeable_state == 'unknown') { | ||
if (retryCount >= maxAttempts) { | ||
core.error(`Get pr status max attempts limit exceeded, payload: ${JSON.stringify(requestData)}`) | ||
|
||
process.exit(1) | ||
} | ||
retryCount++ | ||
await delay(1000) | ||
|
||
return returnPullRequestNumber(requestData) | ||
} | ||
|
||
if (pull_request.data.mergeable) { | ||
core.setOutput('pull_number', requestData.pull_number) | ||
} else { | ||
core.error(`Pull request #${requestData.pull_number} is not mergeable`) | ||
process.exit(1) | ||
} | ||
} | ||
|
||
function delay(ms: number) { | ||
return new Promise((resolve) => setTimeout(resolve, ms)) | ||
} | ||
|
||
run().then() |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.