Skip to content

Commit 1e4ad81

Browse files
authored
fix: get github event payload from context (#20)
* feat: use context.payload to read action event * feat: added build
1 parent 7e1bd11 commit 1e4ad81

File tree

7 files changed

+27
-10
lines changed

7 files changed

+27
-10
lines changed

.pnp.cjs

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Binary file not shown.

build/blogpub.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"devDependencies": {
1818
"#": "link:./test",
1919
"$": "link:./src",
20+
"@octokit/webhooks-definitions": "^3.67.3",
2021
"@types/jest": "^27.4.0",
2122
"@types/js-yaml": "^4.0.5",
2223
"@types/node": "^17.0.8",

src/main.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import Handlebars from 'handlebars';
33
import path from 'path';
44
import * as core from '@actions/core';
55
import { context, getOctokit } from '@actions/github';
6+
import { PushEvent } from '@octokit/webhooks-definitions/schema';
67
import { AxiosError } from 'axios';
78
import { promises as fs } from 'fs';
89

@@ -58,14 +59,12 @@ export async function run() {
5859
const mediumUserId = core.getInput('medium_user_id', { required: true });
5960
const mediumBaseUrl = core.getInput('medium_base_url', { required: false });
6061
const devtoApiKey = core.getInput('devto_api_key', { required: true });
61-
// eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-unsafe-assignment
62-
const eventPayload = require(process.env.GITHUB_EVENT_PATH as string);
6362

6463
const github = getOctokit(ghToken);
6564

6665
const articleFile = await loadArticleFile(github, articlesFolder);
67-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-argument
68-
const articleAlreadyExists = await checkFileExists(github, articleFile.fileName, eventPayload.before);
66+
const before = (context.payload as PushEvent).before;
67+
const articleAlreadyExists = await checkFileExists(github, articleFile.fileName, before);
6968
/* istanbul ignore next */
7069
if (articleAlreadyExists) {
7170
/* istanbul ignore next */

test/main.spec.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,15 @@ jest.mock('@actions/github', () => ({
3030
owner: 'owner',
3131
repo: 'repo',
3232
},
33+
payload: {
34+
before: 'sha'
35+
},
3336
sha: '1234',
3437
},
3538
getOctokit: jest.fn(),
3639
}));
3740
jest.mock('@actions/core');
3841

39-
process.env.GITHUB_EVENT_PATH = 'event.json';
40-
jest.mock('event.json', () => ({
41-
// __esModule: true,
42-
default: { before: 'sha' },
43-
}), { virtual: true });
4442

4543
describe('blogpub', () => {
4644
beforeEach(jest.clearAllMocks);

yarn.lock

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,13 @@ __metadata:
860860
languageName: node
861861
linkType: hard
862862

863+
"@octokit/webhooks-definitions@npm:^3.67.3":
864+
version: 3.68.1
865+
resolution: "@octokit/webhooks-definitions@npm:3.68.1"
866+
checksum: ce479223ab11235c5f59e40bb8ef4fdbc161afd77de0def540d3ce4dc25f2d5beddf159fcee6a585e4aa064ae2f69ae5c87826f6a2a38dc576a175d6a2f76a75
867+
languageName: node
868+
linkType: hard
869+
863870
"@sinonjs/commons@npm:^1.7.0":
864871
version: 1.8.3
865872
resolution: "@sinonjs/commons@npm:1.8.3"
@@ -1725,6 +1732,7 @@ __metadata:
17251732
$: "link:./src"
17261733
"@actions/core": ^1.6.0
17271734
"@actions/github": ^5.0.0
1735+
"@octokit/webhooks-definitions": ^3.67.3
17281736
"@types/jest": ^27.4.0
17291737
"@types/js-yaml": ^4.0.5
17301738
"@types/node": ^17.0.8

0 commit comments

Comments
 (0)