You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by po...@apache.org on 2020/12/27 14:02:26 UTC
[airflow-checks-action] 24/27: Add remote repository support (Fixes
#9) (#10)
This is an automated email from the ASF dual-hosted git repository.
potiuk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/airflow-checks-action.git
commit 9f02872da71b6f558c6a6f190f925dde5e4d8798
Author: MichaĆ Sawicz <mi...@sawicz.net>
AuthorDate: Mon Sep 28 16:21:00 2020 +0200
Add remote repository support (Fixes #9) (#10)
* Add logging of owner/repo and SHA
* Add support for `repo` and `sha` inputs (Fixes #9)
* Add missing comment.
* Revert to defaults being assigned on declaration
* Add missing `required: false`
To keep consistent, even if it's the default:
https://docs.github.com/en/free-pro-team@latest/actions/creating-actions/metadata-syntax-for-github-actions#inputsinput_idrequired
* Add check for invalid `repo` format
---
README.md | 8 +++++
__tests__/main.test.ts | 80 ++++++++++++++++++++++++++++++++++++++++++++++--
action.yml | 6 ++++
dist/index.js | 2 +-
src/inputs.ts | 8 +++++
src/main.ts | 16 ++++++++--
src/namespaces/Inputs.ts | 2 ++
7 files changed, 116 insertions(+), 6 deletions(-)
diff --git a/README.md b/README.md
index e996573..c7aa21c 100644
--- a/README.md
+++ b/README.md
@@ -31,6 +31,14 @@ See the [examples workflow](.github/workflows/examples.yml) for more details and
## Inputs
+### `repo`
+
+_Optional_ The target repository (`owner/repo`) on which to manage the check run. Defaults to the current repository.
+
+### `sha`
+
+_Optional_ The SHA of the target commit. Defaults to the current commit.
+
### `token`
**Required** Your `GITHUB_TOKEN`
diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts
index 5514487..8f4c49e 100644
--- a/__tests__/main.test.ts
+++ b/__tests__/main.test.ts
@@ -7,6 +7,7 @@ test('test runs (creation)', () => {
const options: cp.ExecSyncOptions = {
env: {
GITHUB_REPOSITORY: 'LB/ABC',
+ GITHUB_SHA: 'SHA',
INPUT_TOKEN: 'ABC',
INPUT_NAME: 'ABC',
INPUT_STATUS: 'completed',
@@ -19,7 +20,7 @@ test('test runs (creation)', () => {
const error = e as Error & {stdout: Buffer};
const output = error.stdout.toString();
console.log(output);
- expect(output).toMatch(/::debug::Creating a new Run/);
+ expect(output).toMatch(/::debug::Creating a new Run on LB\/ABC@SHA/);
expect(output).toMatch(/::debug::HttpError: Bad credentials/);
}
});
@@ -29,6 +30,7 @@ test('test runs (update)', () => {
const options: cp.ExecSyncOptions = {
env: {
GITHUB_REPOSITORY: 'LB/ABC',
+ GITHUB_SHA: 'SHA',
INPUT_TOKEN: 'ABC',
INPUT_CHECK_ID: '123',
INPUT_STATUS: 'completed',
@@ -41,9 +43,83 @@ test('test runs (update)', () => {
const error = e as Error & {stdout: Buffer};
const output = error.stdout.toString();
console.log(output);
- expect(output).toMatch(/::debug::Updating a Run/);
+ expect(output).toMatch(/::debug::Updating a Run on LB\/ABC@SHA \(123\)/);
expect(output).toMatch(/::debug::HttpError: Bad credentials/);
}
});
+test('test runs (creation on remote repository)', () => {
+ const entry = path.join(__dirname, '..', 'lib', 'main.js');
+ const options: cp.ExecSyncOptions = {
+ env: {
+ GITHUB_REPOSITORY: 'LB/ABC',
+ GITHUB_SHA: 'SHA',
+ INPUT_TOKEN: 'ABC',
+ INPUT_NAME: 'ABC',
+ INPUT_STATUS: 'completed',
+ INPUT_CONCLUSION: 'success',
+ INPUT_REPO: 'remote/repo',
+ INPUT_SHA: 'DEF',
+ },
+ };
+ try {
+ console.log(cp.execSync(`node ${entry}`, options).toString());
+ } catch (e) {
+ const error = e as Error & {stdout: Buffer};
+ const output = error.stdout.toString();
+ console.log(output);
+ expect(output).toMatch(/::debug::Creating a new Run on remote\/repo@DEF/);
+ expect(output).toMatch(/::debug::HttpError: Bad credentials/);
+ }
+});
+
+test('test runs (update on remote repository)', () => {
+ const entry = path.join(__dirname, '..', 'lib', 'main.js');
+ const options: cp.ExecSyncOptions = {
+ env: {
+ GITHUB_REPOSITORY: 'LB/ABC',
+ GITHUB_SHA: 'SHA',
+ INPUT_TOKEN: 'ABC',
+ INPUT_CHECK_ID: '123',
+ INPUT_STATUS: 'completed',
+ INPUT_CONCLUSION: 'success',
+ INPUT_REPO: 'remote/repo',
+ INPUT_SHA: 'DEF',
+ },
+ };
+ try {
+ console.log(cp.execSync(`node ${entry}`, options).toString());
+ } catch (e) {
+ const error = e as Error & {stdout: Buffer};
+ const output = error.stdout.toString();
+ console.log(output);
+ expect(output).toMatch(/::debug::Updating a Run on remote\/repo@DEF \(123\)/);
+ expect(output).toMatch(/::debug::HttpError: Bad credentials/);
+ }
+});
+
+test('test rejects invalid repo', () => {
+ const entry = path.join(__dirname, '..', 'lib', 'main.js');
+ const options: cp.ExecSyncOptions = {
+ env: {
+ GITHUB_REPOSITORY: 'LB/ABC',
+ GITHUB_SHA: 'SHA',
+ INPUT_TOKEN: 'ABC',
+ INPUT_CHECK_ID: '123',
+ INPUT_STATUS: 'completed',
+ INPUT_CONCLUSION: 'success',
+ INPUT_REPO: 'invalid',
+ INPUT_SHA: 'DEF',
+ },
+ };
+ try {
+ console.log(cp.execSync(`node ${entry}`, options).toString());
+ } catch (e) {
+ const error = e as Error & {stdout: Buffer};
+ const output = error.stdout.toString();
+ console.log(output);
+ expect(output).toMatch(/::debug::Error: repo needs to be in the {owner}\/{repository} format/);
+ }
+});
+
// TODO: add more
diff --git a/action.yml b/action.yml
index 444da5e..3d71d6d 100644
--- a/action.yml
+++ b/action.yml
@@ -5,6 +5,12 @@ branding:
icon: 'check-circle'
color: 'green'
inputs:
+ repo:
+ description: 'the target `owner/repo` to manage the check run on (defaults to the current repository'
+ required: false
+ sha:
+ description: 'the target commit''s SHA (defaults to the current commit)'
+ required: false
token:
description: 'your GITHUB_TOKEN'
required: true
diff --git a/dist/index.js b/dist/index.js
index 1a3450f..0283cd9 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -1 +1 @@
-module.exports=(()=>{var __webpack_modules__={321:function(e,t,r){"use strict";var s=this&&this.__createBinding||(Object.create?function(e,t,r,s){if(s===undefined)s=r;Object.defineProperty(e,s,{enumerable:true,get:function(){return t[r]}})}:function(e,t,r,s){if(s===undefined)s=r;e[s]=t[r]});var o=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:true,value:t})}:function(e,t){e["default"]=t});var n=this&&this.__importStar||function(e [...]
\ No newline at end of file
+module.exports=(()=>{var __webpack_modules__={321:function(e,t,r){"use strict";var s=this&&this.__createBinding||(Object.create?function(e,t,r,s){if(s===undefined)s=r;Object.defineProperty(e,s,{enumerable:true,get:function(){return t[r]}})}:function(e,t,r,s){if(s===undefined)s=r;e[s]=t[r]});var o=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:true,value:t})}:function(e,t){e["default"]=t});var n=this&&this.__importStar||function(e [...]
\ No newline at end of file
diff --git a/src/inputs.ts b/src/inputs.ts
index 32931a1..cac6d1d 100644
--- a/src/inputs.ts
+++ b/src/inputs.ts
@@ -17,6 +17,8 @@ const parseJSON = <T>(getInput: GetInput, property: string): T | undefined => {
};
export const parseInputs = (getInput: GetInput): Inputs.Args => {
+ const repo = getInput('repo');
+ const sha = getInput('sha');
const token = getInput('token', {required: true});
const name = getInput('name');
@@ -28,6 +30,10 @@ export const parseInputs = (getInput: GetInput): Inputs.Args => {
const actionURL = getInput('action_url');
const detailsURL = getInput('details_url');
+ if (repo && repo.split('/').length != 2) {
+ throw new Error('repo needs to be in the {owner}/{repository} format');
+ }
+
if (name && checkIDStr) {
throw new Error(`can only provide 'name' or 'check_id'`);
}
@@ -73,6 +79,8 @@ export const parseInputs = (getInput: GetInput): Inputs.Args => {
}
return {
+ repo,
+ sha,
name,
token,
status,
diff --git a/src/main.ts b/src/main.ts
index d03548a..ce440ae 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -20,15 +20,25 @@ async function run(): Promise<void> {
owner: github.context.repo.owner,
repo: github.context.repo.repo,
};
- const sha = github.context.sha;
+ let sha = github.context.sha;
+
+ if (inputs.repo) {
+ const repo = inputs.repo.split('/');
+ ownership.owner = repo[0];
+ ownership.repo = repo[1];
+ }
+
+ if (inputs.sha) {
+ sha = inputs.sha;
+ }
if (isCreation(inputs)) {
- core.debug(`Creating a new Run`);
+ core.debug(`Creating a new Run on ${ownership.owner}/${ownership.repo}@${sha}`);
const id = await createRun(octokit, inputs.name, sha, ownership, inputs);
core.setOutput('check_id', id);
} else {
const id = inputs.checkID;
- core.debug(`Updating a Run (${id})`);
+ core.debug(`Updating a Run on ${ownership.owner}/${ownership.repo}@${sha} (${id})`);
await updateRun(octokit, id, ownership, inputs);
}
core.debug(`Done`);
diff --git a/src/namespaces/Inputs.ts b/src/namespaces/Inputs.ts
index 8363cd9..12cdca8 100644
--- a/src/namespaces/Inputs.ts
+++ b/src/namespaces/Inputs.ts
@@ -1,6 +1,8 @@
import {RestEndpointMethodTypes} from '@octokit/rest';
interface ArgsBase {
+ repo?: string;
+ sha?: string;
token: string;
conclusion?: Conclusion;
status: Status;