typescript-github-action-template 0.1.19 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/getOctokit.d.ts +6 -0
- package/dist/getOctokit.js +39 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +45 -0
- package/package.json +10 -8
- package/lib/index.d.ts +0 -1
- package/lib/index.js +0 -20
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type Octokit } from '@octokit/core/dist-types/index.js';
|
|
2
|
+
import { type PaginateInterface } from '@octokit/plugin-paginate-rest';
|
|
3
|
+
import { type Api } from '@octokit/plugin-rest-endpoint-methods/dist-types/types.js';
|
|
4
|
+
export declare function getOctokit(githubToken: string): Octokit & Api & {
|
|
5
|
+
paginate: PaginateInterface;
|
|
6
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { GitHub, getOctokitOptions } from '@actions/github/lib/utils.js';
|
|
2
|
+
import { retry } from '@octokit/plugin-retry';
|
|
3
|
+
import { throttling } from '@octokit/plugin-throttling';
|
|
4
|
+
export function getOctokit(githubToken) {
|
|
5
|
+
const Octokit = GitHub.plugin(throttling, retry);
|
|
6
|
+
const octokit = new Octokit(getOctokitOptions(githubToken, {
|
|
7
|
+
throttle: {
|
|
8
|
+
onRateLimit: (retryAfter, options, _, retryCount) => {
|
|
9
|
+
if (retryCount === 0) {
|
|
10
|
+
octokit.log.warn(`Request quota exhausted for request ${options.method} ${options.url}`);
|
|
11
|
+
octokit.log.info(`Retrying after ${retryAfter} seconds!`);
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
octokit.log.error(`Request quota exhausted for request ${options.method} ${options.url}`);
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
onSecondaryRateLimit: (retryAfter, options, _, retryCount) => {
|
|
19
|
+
if (retryCount === 0) {
|
|
20
|
+
octokit.log.warn(`Abuse detected for request ${options.method} ${options.url}`);
|
|
21
|
+
octokit.log.info(`Retrying after ${retryAfter} seconds!`);
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
octokit.log.warn(`Abuse detected for request ${options.method} ${options.url}`);
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
retry: {
|
|
30
|
+
doNotRetry: ['429'],
|
|
31
|
+
},
|
|
32
|
+
}));
|
|
33
|
+
octokit.graphql = octokit.graphql.defaults({
|
|
34
|
+
headers: {
|
|
35
|
+
'X-GitHub-Next-Global-ID': 1,
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
return octokit;
|
|
39
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getLogin(githubToken: string): Promise<string>;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { error, getInput, getState, notice, saveState, setFailed, } from '@actions/core';
|
|
11
|
+
import { getOctokit } from './getOctokit.js';
|
|
12
|
+
export function getLogin(githubToken) {
|
|
13
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
14
|
+
const octokit = getOctokit(githubToken);
|
|
15
|
+
const { viewer: { login }, } = yield octokit.graphql(`
|
|
16
|
+
query {
|
|
17
|
+
viewer {
|
|
18
|
+
login
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
`, {});
|
|
22
|
+
return login;
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
function run() {
|
|
26
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
const githubToken = getInput('github-token');
|
|
28
|
+
const login = yield getLogin(githubToken);
|
|
29
|
+
saveState('login', login);
|
|
30
|
+
notice(`Hello, ${login}!`);
|
|
31
|
+
error('Please implement this Action.');
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
function cleanup() {
|
|
35
|
+
const login = getState('login');
|
|
36
|
+
notice(`Goodbye, ${login}!`);
|
|
37
|
+
error('Please implemented or removed Action cleanup.');
|
|
38
|
+
}
|
|
39
|
+
if (!getState('isPost')) {
|
|
40
|
+
saveState('isPost', 'true');
|
|
41
|
+
run().catch((error) => setFailed(error));
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
cleanup();
|
|
45
|
+
}
|
package/package.json
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typescript-github-action-template",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "A template to create custom GitHub Action with TypeScript/JavaScript.",
|
|
5
|
-
"main": "
|
|
6
|
-
"types": "
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.js",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"scripts": {
|
|
9
|
-
"build": "rm -rf
|
|
10
|
-
"
|
|
9
|
+
"build": "rm -rf dist && yarn tsc",
|
|
10
|
+
"bundle": "rm -rf bundle && yarn ncc build src/index.ts --external eslint --source-map --license licenses.txt --out bundle",
|
|
11
11
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
12
12
|
"lint": "eslint -c eslint.config.js",
|
|
13
13
|
"_postinstall": "is-ci || husky install",
|
|
14
|
-
"prepublishOnly": "pinst --disable",
|
|
14
|
+
"prepublishOnly": "pinst --disable && yarn build",
|
|
15
15
|
"postpublish": "pinst --enable",
|
|
16
|
-
"preversion": "yarn && yarn build && yarn
|
|
16
|
+
"preversion": "yarn && yarn build && yarn bundle"
|
|
17
17
|
},
|
|
18
18
|
"repository": {
|
|
19
19
|
"type": "git",
|
|
@@ -47,7 +47,9 @@
|
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"@actions/core": "^1.10.0",
|
|
50
|
-
"@actions/github": "^6.0.0"
|
|
50
|
+
"@actions/github": "^6.0.0",
|
|
51
|
+
"@octokit/plugin-retry": "^7.1.1",
|
|
52
|
+
"@octokit/plugin-throttling": "^9.3.0"
|
|
51
53
|
},
|
|
52
54
|
"lint-staged": {
|
|
53
55
|
"*.(ts,js)": "yarn lint --fix",
|
package/lib/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/lib/index.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const core_1 = require("@actions/core");
|
|
4
|
-
const github_1 = require("@actions/github");
|
|
5
|
-
function run() {
|
|
6
|
-
if (!(0, core_1.getState)('isPost')) {
|
|
7
|
-
(0, core_1.saveState)('isPost', 'true');
|
|
8
|
-
}
|
|
9
|
-
(0, core_1.info)(`This is the Action context: ${JSON.stringify(github_1.context)}`);
|
|
10
|
-
(0, core_1.error)('Action needs to be implemented.');
|
|
11
|
-
}
|
|
12
|
-
function cleanup() {
|
|
13
|
-
(0, core_1.error)('Post action needs to be implemented or removed.');
|
|
14
|
-
}
|
|
15
|
-
if (!(0, core_1.getState)('isPost')) {
|
|
16
|
-
run();
|
|
17
|
-
}
|
|
18
|
-
else {
|
|
19
|
-
cleanup();
|
|
20
|
-
}
|