Files

Return to Package Diff Home.
Brought to you by Intrinsic.

Package Diff: @cypress/set-commit-status @ 1.1.0 .. 1.3.4

dist/bin/set-commit-status.js

@@ -12,8 +12,8 @@
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
-const __1 = require("..");
const arg_1 = __importDefault(require("arg"));
+const __1 = require("../");
const args = arg_1.default({
// repo info
'--owner': String,
@@ -23,7 +23,7 @@
'--state': String,
'--description': String,
'--url': String,
- '--context': String
+ '--context': String,
});
if (!args['--owner']) {
console.error('Missing --owner name');
@@ -41,18 +41,19 @@
return __awaiter(this, void 0, void 0, function* () {
const params = __1.GitHub.getFromEnvironment();
const gh = __1.GitHub.createGithubAppClient(params);
- const state = args["--state"] || __1.GitHub.StatusState.pending;
+ const state = args['--state'] || __1.GitHub.StatusState.pending;
yield __1.GitHub.setCommitStatus({
owner: args['--owner'],
repo: args['--repo'],
sha: args['--sha'],
- state,
+ context: args['--context'],
description: args['--description'],
- context: args['--context']
+ targetUrl: args['--url'],
+ state,
}, gh);
});
}
-setCommitStatus().catch(e => {
+setCommitStatus().catch((e) => {
console.error(e.message);
process.exit(2);
});

dist/index.d.ts

@@ -4,6 +4,13 @@
* Url string, should start with "https://..."
*/
export declare type url = string;
+export declare const getAppVeyorBuildUrl: () => string | undefined;
+/**
+ * Returns the current build job url based on built-in environment variables on various CIs
+ * @see CircleCI https://circleci.com/docs/2.0/env-vars/
+ * @see AppVeyor https://www.appveyor.com/docs/environment-variables/
+ */
+export declare const getTargetUrl: () => string | undefined;
export declare namespace GitHub {
/**
* Full commit SHA (40 hex characters, lowercase)
@@ -34,9 +41,9 @@
repo: string;
sha: string;
state: StatusState;
+ context: string;
targetUrl?: url;
description?: string;
- context?: string;
};
function setCommitStatus(options: CommitStatusOptions, gh: octokit): Promise<void>;
}

dist/index.js

@@ -38,6 +38,26 @@
userAgent: 'octokit/rest.js v16.23.2',
});
}
+exports.getAppVeyorBuildUrl = () => {
+ if (!process.env.APPVEYOR) {
+ return;
+ }
+ const { APPVEYOR_URL, APPVEYOR_ACCOUNT_NAME, APPVEYOR_PROJECT_SLUG, APPVEYOR_BUILD_ID, } = process.env;
+ if (!APPVEYOR_URL ||
+ !APPVEYOR_ACCOUNT_NAME ||
+ !APPVEYOR_BUILD_ID ||
+ !APPVEYOR_PROJECT_SLUG) {
+ console.error('Hmm, cannot find build environment variables on AppVeyor CI');
+ return;
+ }
+ return `${APPVEYOR_URL}/project/${APPVEYOR_ACCOUNT_NAME}/${APPVEYOR_PROJECT_SLUG}/builds/${APPVEYOR_BUILD_ID}`;
+};
+/**
+ * Returns the current build job url based on built-in environment variables on various CIs
+ * @see CircleCI https://circleci.com/docs/2.0/env-vars/
+ * @see AppVeyor https://www.appveyor.com/docs/environment-variables/
+ */
+exports.getTargetUrl = () => process.env.CIRCLE_BUILD_URL || exports.getAppVeyorBuildUrl();
var GitHub;
(function (GitHub) {
/**
@@ -87,17 +107,23 @@
function setCommitStatus(options, gh) {
return __awaiter(this, void 0, void 0, function* () {
debug('setting commit status %o', options);
- // https://octokit.github.io/rest.js/#api-Repos-createStatus
- yield gh.repos.createStatus({
+ let targetUrl = options.targetUrl || exports.getTargetUrl();
+ const ghOptions = {
owner: options.owner,
repo: options.repo,
sha: options.sha,
state: options.state || StatusState.pending,
- target_url: options.targetUrl,
+ target_url: targetUrl,
description: options.description,
context: options.context,
- });
- debug('created commit status: %s/%s sha %s state %s', options.owner, options.repo, options.sha, options.state);
+ };
+ debug('resolved commit status options %o', ghOptions);
+ // https://octokit.github.io/rest.js/#api-Repos-createStatus
+ yield gh.repos.createStatus(ghOptions);
+ debug('created commit status: %s/%s sha %s state %s', ghOptions.owner, ghOptions.repo, ghOptions.sha, ghOptions.state);
+ if (ghOptions.target_url) {
+ debug('with details at %s', ghOptions.target_url);
+ }
});
}
GitHub.setCommitStatus = setCommitStatus;

package.json

@@ -1,9 +1,9 @@
{
"name": "@cypress/set-commit-status",
- "version": "1.1.0",
+ "version": "1.3.4",
"description": "Set GitHub commit status",
"author": "Gleb Bahmutov <gleb.bahmutov@gmail.com> (https://glebbahmutov.com)",
- "homepage": "https://github.com/cypress-io/release-bits#readme",
+ "homepage": "https://github.com/cypress-io/release-automations/tree/master/packages/set-commit-status#readme",
"license": "ISC",
"main": "dist/index.js",
"types": "dist/index.d.ts",
@@ -13,7 +13,9 @@
},
"files": [
"src",
- "dist"
+ "!src/*test.ts",
+ "dist",
+ "!dist/**/*test.js"
],
"alias": {
"set-commit-status": "dist/bin/set-commit-status.js"
@@ -23,15 +25,15 @@
},
"repository": {
"type": "git",
- "url": "git+https://github.com/cypress-io/release-bits.git"
+ "url": "git+https://github.com/cypress-io/release-automations.git"
},
"scripts": {
- "test": "echo \"Error: run tests from root\" && exit 1",
+ "test": "ava-ts src/*test.ts",
"tsc": "tsc",
"prepare": "tsc"
},
"bugs": {
- "url": "https://github.com/cypress-io/release-bits/issues"
+ "url": "https://github.com/cypress-io/release-automations/issues"
},
"dependencies": {
"@octokit/app": "2.2.2",
@@ -41,5 +43,11 @@
"debug": "4.1.1",
"lazy-ass": "1.6.0"
},
- "gitHead": "6264fe56f51ee924aeb1e67d94f916c79ae253b5"
+ "devDependencies": {
+ "ava": "^1.4.1",
+ "ava-ts": "0.25.2",
+ "mocked-env": "^1.2.4",
+ "ts-node": "^8.1.0"
+ },
+ "gitHead": "c7fb0ed04963a3ecd7fc95f2135e5f59e24da6df"
}

src/bin/set-commit-status.ts

@@ -1,7 +1,7 @@
#!/usr/bin/env node
-import { GitHub } from '..'
import arg from 'arg'
+import { GitHub } from '../'
const args = arg({
// repo info
@@ -12,7 +12,7 @@
'--state': String,
'--description': String,
'--url': String,
- '--context': String
+ '--context': String,
})
if (!args['--owner']) {
@@ -34,21 +34,24 @@
const params = GitHub.getFromEnvironment()
const gh = GitHub.createGithubAppClient(params)
- const state = args["--state"] as GitHub.StatusState || GitHub.StatusState.pending
+ const state =
+ (args['--state'] as GitHub.StatusState) || GitHub.StatusState.pending
+
await GitHub.setCommitStatus(
{
owner: args['--owner']!,
repo: args['--repo']!,
sha: args['--sha']!,
- state,
+ context: args['--context']!,
description: args['--description'],
- context: args['--context']
+ targetUrl: args['--url'],
+ state,
},
gh
)
}
-setCommitStatus().catch(e => {
+setCommitStatus().catch((e) => {
console.error(e.message)
process.exit(2)
})

src/index.ts

@@ -34,6 +34,36 @@
})
}
+export const getAppVeyorBuildUrl = () => {
+ if (!process.env.APPVEYOR) {
+ return
+ }
+ const {
+ APPVEYOR_URL,
+ APPVEYOR_ACCOUNT_NAME,
+ APPVEYOR_PROJECT_SLUG,
+ APPVEYOR_BUILD_ID,
+ } = process.env
+ if (
+ !APPVEYOR_URL ||
+ !APPVEYOR_ACCOUNT_NAME ||
+ !APPVEYOR_BUILD_ID ||
+ !APPVEYOR_PROJECT_SLUG
+ ) {
+ console.error('Hmm, cannot find build environment variables on AppVeyor CI')
+ return
+ }
+ return `${APPVEYOR_URL}/project/${APPVEYOR_ACCOUNT_NAME}/${APPVEYOR_PROJECT_SLUG}/builds/${APPVEYOR_BUILD_ID}`
+}
+
+/**
+ * Returns the current build job url based on built-in environment variables on various CIs
+ * @see CircleCI https://circleci.com/docs/2.0/env-vars/
+ * @see AppVeyor https://www.appveyor.com/docs/environment-variables/
+ */
+export const getTargetUrl = () =>
+ process.env.CIRCLE_BUILD_URL || getAppVeyorBuildUrl()
+
export namespace GitHub {
/**
* Full commit SHA (40 hex characters, lowercase)
@@ -101,9 +131,9 @@
repo: string
sha: string
state: StatusState
+ context: string
targetUrl?: url
description?: string
- context?: string
}
export async function setCommitStatus(
@@ -112,24 +142,31 @@
) {
debug('setting commit status %o', options)
- // https://octokit.github.io/rest.js/#api-Repos-createStatus
- await gh.repos.createStatus({
+ let targetUrl = options.targetUrl || getTargetUrl()
+ const ghOptions = {
owner: options.owner,
repo: options.repo,
sha: options.sha,
state: options.state || StatusState.pending,
- target_url: options.targetUrl,
+ target_url: targetUrl,
description: options.description,
context: options.context,
- })
+ }
+ debug('resolved commit status options %o', ghOptions)
+
+ // https://octokit.github.io/rest.js/#api-Repos-createStatus
+ await gh.repos.createStatus(ghOptions)
debug(
'created commit status: %s/%s sha %s state %s',
- options.owner,
- options.repo,
- options.sha,
- options.state
+ ghOptions.owner,
+ ghOptions.repo,
+ ghOptions.sha,
+ ghOptions.state
)
+ if (ghOptions.target_url) {
+ debug('with details at %s', ghOptions.target_url)
+ }
}
}