Skip to content

Commit

Permalink
chore: update dependencies + skip checks for service account team
Browse files Browse the repository at this point in the history
  • Loading branch information
B4nan committed Feb 5, 2024
1 parent b7b85d3 commit 0417ac6
Show file tree
Hide file tree
Showing 13 changed files with 29,693 additions and 13,179 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "@apify/eslint-config-ts",
"rules": {
"import/extensions": ["off", "never"]
"import/extensions": ["off", "never"],
"no-void": ["off", "never"]
}
}
2 changes: 1 addition & 1 deletion .github/workflows/pr_toolkit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-20.04
steps:
- name: clone local repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: run pull-request-toolkit action
uses: ./
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
# Pull request toolkit

This action automates a couple of processes connected with the management of Github pull requests.
This action automates a couple of processes connected with the management of GitHub pull requests.

# What it does

- Assigns PR to its creator.
- Fills missing milestone with a current milestone from Zenhub.
- Fills a missing milestone with a current milestone from Zenhub.
- Assigns a team label (`t-[teamName]`) to the pull request.
- Makes sure that:
- PR is either linked with epic or issue or labeled as `adhoc`
- PR itself or linked issue is estimated

## Wishlist / TODOs

- Github action for publishing of a new version.
- Github action for lint and tests execution.
- GitHub action for publishing of a new version.
- GitHub action for lint and tests execution.
- Use Docker image with runtime typescript compilation instead of committing a dist directory.

# Action input

| Name | Description | Example | Required |
| ---------------| -------------------------------------------------- | ---------------| -------- |
| `repo-token` | Repository Github token | `github-token` | yes |
| `org-token` | Github token with read only access to organization | `github-token` | yes |
| `zenhub-token` | Github token with read only access to organization | `zenhub-token` | yes |
|----------------|----------------------------------------------------|----------------|----------|
| `repo-token` | Repository GitHub token | `github-token` | yes |
| `org-token` | GitHub token with read only access to organization | `github-token` | yes |
| `zenhub-token` | GitHub token with read only access to organization | `zenhub-token` | yes |

# Example usage

Expand Down
33,041 changes: 27,248 additions & 5,793 deletions dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module.exports = {
moduleFileExtensions: ['js', 'ts'],
testEnvironment: 'node',
testMatch: ['**/*.test.ts'],
testRunner: 'jest-circus/runner',
transform: {
'^.+\\.ts$': 'ts-jest'
},
Expand Down
9,691 changes: 2,379 additions & 7,312 deletions package-lock.json

Large diffs are not rendered by default.

31 changes: 15 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,23 @@
"author": "Apify team",
"license": "Apache",
"dependencies": {
"@actions/core": "^1.8.2",
"@actions/github": "^5.0.3",
"axios": "^1.2.3"
"@actions/core": "^1.10.1",
"@actions/github": "^6.0.0",
"axios": "^1.6.7"
},
"devDependencies": {
"@apify/eslint-config-ts": "^0.2.3",
"@types/jest": "^27.5.1",
"@types/node": "^16.0.38",
"@typescript-eslint/eslint-plugin": "^5.27.0",
"@typescript-eslint/parser": "^5.27.0",
"@vercel/ncc": "^0.34.0",
"eslint": "^8.16.0",
"eslint-plugin-github": "^4.3.6",
"eslint-plugin-jest": "^26.4.6",
"jest": "^28.1.0",
"jest-circus": "^28.1.0",
"@apify/eslint-config-ts": "^0.4.1",
"@types/jest": "^29.5.12",
"@types/node": "^20.11.16",
"@typescript-eslint/eslint-plugin": "^6.20.0",
"@typescript-eslint/parser": "^6.20.0",
"@vercel/ncc": "^0.38.1",
"eslint": "^8.56.0",
"eslint-plugin-github": "^4.10.1",
"eslint-plugin-jest": "^27.6.3",
"jest": "^29.7.0",
"js-yaml": "^4.1.0",
"ts-jest": "^28.0.3",
"typescript": "^4.7.2"
"ts-jest": "^29.1.2",
"typescript": "^5.3.3"
}
}
4 changes: 2 additions & 2 deletions src/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ export const TEAM_NAME_TO_LABEL: { [name: string]: string} = {
export const LINKING_CHECK_RETRIES = 8;
export const LINKING_CHECK_DELAY_MILLIS = 15 * 1000;

export const TEAMS_NOT_USING_ZENHUB = ['put-some-team-here'];
export const TEAMS_NOT_USING_ZENHUB = ['put-some-team-here', 'Service Account'];

// Excludes the team from the milestone, correct linking and estimate checks.
export const SKIP_MILESTONES_AND_ESTIMATES_FOR_TEAMS = ['Docs'];
export const SKIP_MILESTONES_AND_ESTIMATES_FOR_TEAMS = ['Docs', 'Service Account'];

export const TESTED_LABEL_NAME = 'tested';
3 changes: 2 additions & 1 deletion src/helpers.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// import { getOctokit } from '@actions/github';
import { components } from '@octokit/openapi-types/types.d';
import { components } from '@octokit/openapi-types';

import {
findCurrentTeamMilestone,
getTeamLabelName,
Expand Down
28 changes: 14 additions & 14 deletions src/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import axios from 'axios';
import * as core from '@actions/core';
import { type getOctokit } from '@actions/github';
import { components } from '@octokit/openapi-types/types.d';
import { Context } from '@actions/github/lib/context.d';
import { components } from '@octokit/openapi-types/types.d';
import axios from 'axios';

import {
ORGANIZATION,
Expand Down Expand Up @@ -72,7 +72,7 @@ export async function findUsersTeamName(orgOctokit: OctokitType, userLogin: stri
}

return teamName;
};
}

/**
* Finds a current milestone for a given team.
Expand All @@ -96,7 +96,7 @@ export function findCurrentTeamMilestone(milestones: Milestone[], teamName: stri
if (!foundMilestone) throw new Error(`Cannot find milestone for "${teamName}" team`);

return foundMilestone;
};
}

/**
* Configures PR assignee to be the same as PR creater.
Expand Down Expand Up @@ -144,7 +144,7 @@ export async function fillCurrentMilestone(context: Context, octokit: OctokitTyp
*/
export function getTeamLabelName(teamName: string): string {
return TEAM_NAME_TO_LABEL[teamName] || `t-${teamName.toLowerCase()}`;
};
}

/**
* Assigns team label to the pull request.
Expand All @@ -158,7 +158,7 @@ export async function addTeamLabel(context: Context, octokit: OctokitType, pullR
per_page: 100, // Max
});

const isExistingLabel = labels.some((existingLabel) => existingLabel.name === teamLabelName);
const isExistingLabel = labels.some((existingLabel: { name: string }) => existingLabel.name === teamLabelName);
if (!isExistingLabel) await fail(pullRequest, `Team label "${teamLabelName}" of team ${teamName} does not exists!`, octokit);

await octokit.rest.issues.addLabels({
Expand Down Expand Up @@ -271,7 +271,7 @@ export async function isRepoIncludedInZenHubWorkspace(repositoryName: string): P
} while (pageInfo.hasNextPage);

return repositories.map((repo) => repo.name).includes(repositoryName);
};
}

/**
* Makes sure that:
Expand Down Expand Up @@ -308,7 +308,7 @@ export async function ensureCorrectLinkingAndEstimates(pullRequest: PullRequest,
const issueEstimate = issueGraphqlResponse.data.data.issueByInfo.estimate?.value;

if (!pullRequestEstimate && !issueEstimate) await fail(pullRequest, 'None of the pull request and linked issue has estimate', octokit, isDryRun);
};
}

/**
* Adds a comment describing what is wrong with the pull request setup and then fails the action.
Expand Down Expand Up @@ -348,7 +348,7 @@ export function getLinkedIssue(timelineItems: ZenhubTimelineItem[]): ZenhubIssue
...lastItem.data.issue,
repo: lastItem.data.issue_repository,
};
};
}

/**
* Processes a track record of ZenHub events for a PR and returns a list of epics that are currently linked to the PR.
Expand All @@ -370,7 +370,7 @@ export function getLinkedEpics(timelineItems: ZenhubTimelineItem[]): ZenhubIssue
}

return [...connectedEpics.values()];
};
}

export function isTestFilePath(filePath: string): boolean {
const testFileNameRegex = /(\.|_|\w)*tests?(\.|_|\w)*\.\w{2,3}$/;
Expand All @@ -379,7 +379,7 @@ export function isTestFilePath(filePath: string): boolean {
|| filePath.includes('/tests/')
|| filePath.startsWith('test/')
|| testFileNameRegex.test(filePath);
};
}

/**
* Fetches a list of changed files and mark those that contain changes in test files.
Expand All @@ -397,14 +397,14 @@ export async function isPullRequestTested(octokit: OctokitType, pullRequest: Pul
console.log(`- ${testFilePaths.join('\n- ')}`); // eslint-disable-line no-console

return testFilePaths.length > 0;
};
}

/**
* Retries given function `retries` times with `delayMillis` delay between each attempt if the function fails.
*/
export async function retry(func: (isLastAttempt: boolean) => Promise<void>, retries: number, delayMillis: number): Promise<void> {
let currentRetry = 0;
while (true) {
while (true) { // eslint-disable-line no-constant-condition
try {
const isLastAttempt = currentRetry === retries;

Expand All @@ -418,4 +418,4 @@ export async function retry(func: (isLastAttempt: boolean) => Promise<void>, ret
currentRetry++;
}
}
};
}
25 changes: 13 additions & 12 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import { components } from '@octokit/openapi-types/types.d';
import * as core from '@actions/core';
import * as github from '@actions/github';
import { components } from '@octokit/openapi-types';

import {
TEAM_LABEL_PREFIX,
LINKING_CHECK_RETRIES,
LINKING_CHECK_DELAY_MILLIS,
TEAMS_NOT_USING_ZENHUB,
ORGANIZATION,
TESTED_LABEL_NAME,
SKIP_MILESTONES_AND_ESTIMATES_FOR_TEAMS,
} from './consts';
import {
assignPrCreator,
fillCurrentMilestone,
Expand All @@ -11,15 +21,6 @@ import {
isRepoIncludedInZenHubWorkspace,
retry,
} from './helpers';
import {
TEAM_LABEL_PREFIX,
LINKING_CHECK_RETRIES,
LINKING_CHECK_DELAY_MILLIS,
TEAMS_NOT_USING_ZENHUB,
ORGANIZATION,
TESTED_LABEL_NAME,
SKIP_MILESTONES_AND_ESTIMATES_FOR_TEAMS,
} from './consts';

type Assignee = components['schemas']['simple-user'];
type Label = components['schemas']['label'];
Expand Down Expand Up @@ -137,7 +138,7 @@ async function run(): Promise<void> {
// On the other hand, this is a check that author of the PR correctly filled in the details.
// I.e., that the PR is linked to the ZenHub issue and that the estimate is set either on issue or on the PR.
await retry(
(isLastAttempt) => ensureCorrectLinkingAndEstimates(pullRequest, repoOctokit, !isLastAttempt),
async (isLastAttempt) => ensureCorrectLinkingAndEstimates(pullRequest, repoOctokit, !isLastAttempt),
LINKING_CHECK_RETRIES,
LINKING_CHECK_DELAY_MILLIS,
);
Expand All @@ -152,4 +153,4 @@ async function run(): Promise<void> {
}
}

run();
void run();
25 changes: 8 additions & 17 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
{
"compilerOptions": {
"target": "ES2018", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"outDir": "./lib", /* Redirect output structure to the directory. */
"rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
"strict": true, /* Enable all strict type-checking options. */
"noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */

"lib": [
"dom",
"es2020.string",
"es2020.promise",
"es2019.array",
"es2018.asynciterable",
"dom.iterable"
]
"target": "ES2022",
"module": "commonjs",
"outDir": "./lib",
"rootDir": "./src",
"strict": true,
"esModuleInterop": true,
"lib": []
},

"include": ["."],
"exclude": ["node_modules"]
}

0 comments on commit 0417ac6

Please sign in to comment.