Skip to content

Commit

Permalink
Merge pull request #29 from movableink/fix-node-20
Browse files Browse the repository at this point in the history
Update release to work on node 20
  • Loading branch information
duncaan authored Jul 23, 2024
2 parents 0dfc98b + 5c5d4c0 commit 634a1b7
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 2,393 deletions.
18 changes: 4 additions & 14 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,15 @@ name: Verify

on:
push:
branches: [ master ]
branches: [ master, v* ]
pull_request:
branches: [ master ]
branches: [ master, v* ]

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: volta-cli/action@v1
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn config get cacheFolder)"
- uses: actions/cache@v4
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- run: yarn install
- run: yarn test
- run: npm install
- run: npm test
1 change: 0 additions & 1 deletion .yarnrc.yml

This file was deleted.

12 changes: 10 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,16 @@ if (!fs.existsSync(`${__dirname}/node_modules`)) {
}

const github = require('@actions/github');
const octokit = github.getOctokit(process.env.GITHUB_TOKEN);

const action = require('./lib/action');

const octokit = new github.GitHub(process.env.GITHUB_TOKEN);

action(github.context, octokit);
console.log(`Event Name: ${github.context.eventName}`); // Debugging: Log the event name

// Check if the event is a pull request event or pull request target event
if (github.context.eventName === 'pull_request' || github.context.eventName === 'pull_request_target') {
action(github.context, octokit);
} else {
console.log('This action only runs on pull request events.');
}
7 changes: 4 additions & 3 deletions lib/action.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const core = require('@actions/core');


// Matches
// [ch49555] or [sc-49555] or [sc49555] ticket reference
// ch49555/branch-name or sc49555/branch-name or sc-49555/branch-name
Expand All @@ -9,7 +10,7 @@ const shortcutRegex = /(\[ch\d+\])|(ch\d+\/)|(\[sc\d+\])|(sc\d+\/)|(\[sc-\d+\])|
// unfortunately the only way is to name them with one of these:
const jobNames = ['Shortcut', 'Check for story ID'];

module.exports = async function(context, api) {
module.exports = async function (context, api) {
const { repository, pull_request } = context.payload;

const repoInfo = {
Expand Down Expand Up @@ -44,7 +45,7 @@ module.exports = async function(context, api) {
if (process.env.GITHUB_TOKEN) {
// If there are any previously failed CH checks, set them to neutral
// since we want this check to override those.
const checkList = await api.checks.listForRef(repoInfo);
const checkList = await api.rest.checks.listForRef(repoInfo);
const { check_runs } = checkList.data;

const shortcutChecks = check_runs.filter(r => jobNames.includes(r.name));
Expand All @@ -53,7 +54,7 @@ module.exports = async function(context, api) {
for (let check of completedChecks) {
console.log(`Updating ${check.id} check to neutral status`);

await api.checks.update({
await api.rest.checks.update({
...repoInfo,
check_run_id: check.id,
conclusion: 'neutral'
Expand Down
96 changes: 50 additions & 46 deletions lib/action.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,11 @@ describe('pr-lint-action', () => {

describe('checking status', () => {
beforeEach(() => {
api.checks = {
listForRef: () => ({ data: { check_runs: [] } }),
update: () => {}
api.rest = {
checks: {
listForRef: () => ({ data: { check_runs: [] } }),
update: () => {}
}
};
});

Expand Down Expand Up @@ -179,40 +181,42 @@ describe('pr-lint-action', () => {

describe('clearing old checks', () => {
beforeEach(() => {
api.checks = {
listForRef: () => ({
data: {
check_runs: [
{
// this is us, ignore
id: 1,
name: 'Shortcut',
status: 'in_progress',
conclusion: 'neutral'
},
{
id: 2,
name: 'Shortcut',
status: 'completed',
conclusion: 'failure'
},
{
id: 3,
name: 'Shortcut',
status: 'completed',
conclusion: 'failure'
},
{
// this is travis, ignore
id: 4,
name: 'Travis',
status: 'completed',
conclusion: 'failure'
}
]
}
}),
update: jest.fn()
api.rest = {
checks: {
listForRef: () => ({
data: {
check_runs: [
{
// this is us, ignore
id: 1,
name: 'Shortcut',
status: 'in_progress',
conclusion: 'neutral'
},
{
id: 2,
name: 'Shortcut',
status: 'completed',
conclusion: 'failure'
},
{
id: 3,
name: 'Shortcut',
status: 'completed',
conclusion: 'failure'
},
{
// this is travis, ignore
id: 4,
name: 'Travis',
status: 'completed',
conclusion: 'failure'
}
]
}
}),
update: jest.fn()
}
};
});

Expand All @@ -222,17 +226,17 @@ describe('pr-lint-action', () => {

await action(context, api);

expect(api.checks.update).toHaveBeenCalledTimes(2);
expect(api.rest.checks.update).toHaveBeenCalledTimes(2);

expect(api.checks.update).toHaveBeenNthCalledWith(1, {
expect(api.rest.checks.update).toHaveBeenNthCalledWith(1, {
check_run_id: 2,
owner: 'movableink',
repo: 'pr-shortcut-lint-action-test',
ref: 'fix_things',
conclusion: 'neutral'
});

expect(api.checks.update).toHaveBeenNthCalledWith(2, {
expect(api.rest.checks.update).toHaveBeenNthCalledWith(2, {
check_run_id: 3,
owner: 'movableink',
repo: 'pr-shortcut-lint-action-test',
Expand All @@ -248,17 +252,17 @@ describe('pr-lint-action', () => {

await action(context, api);

expect(api.checks.update).toHaveBeenCalledTimes(2);
expect(api.rest.checks.update).toHaveBeenCalledTimes(2);

expect(api.checks.update).toHaveBeenNthCalledWith(1, {
expect(api.rest.checks.update).toHaveBeenNthCalledWith(1, {
check_run_id: 2,
owner: 'movableink',
repo: 'pr-shortcut-lint-action-test',
ref: 'fix_things',
conclusion: 'neutral'
});

expect(api.checks.update).toHaveBeenNthCalledWith(2, {
expect(api.rest.checks.update).toHaveBeenNthCalledWith(2, {
check_run_id: 3,
owner: 'movableink',
repo: 'pr-shortcut-lint-action-test',
Expand All @@ -273,17 +277,17 @@ describe('pr-lint-action', () => {

await action(context, api);

expect(api.checks.update).toHaveBeenCalledTimes(2);
expect(api.rest.checks.update).toHaveBeenCalledTimes(2);

expect(api.checks.update).toHaveBeenNthCalledWith(1, {
expect(api.rest.checks.update).toHaveBeenNthCalledWith(1, {
check_run_id: 2,
owner: 'movableink',
repo: 'pr-shortcut-lint-action-test',
ref: 'fix_things',
conclusion: 'neutral'
});

expect(api.checks.update).toHaveBeenNthCalledWith(2, {
expect(api.rest.checks.update).toHaveBeenNthCalledWith(2, {
check_run_id: 3,
owner: 'movableink',
repo: 'pr-shortcut-lint-action-test',
Expand Down
Loading

0 comments on commit 634a1b7

Please sign in to comment.