Skip to content

Commit

Permalink
Merge pull request #66 from mlg87/update-deps
Browse files Browse the repository at this point in the history
fix(team-requested-reviewers): attempt to clean up getRequestedReview…
  • Loading branch information
mlg87 authored May 11, 2024
2 parents d37232d + 4ee76d4 commit a713396
Show file tree
Hide file tree
Showing 17 changed files with 2,748 additions and 3,684 deletions.
26 changes: 5 additions & 21 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
fetch-depth: 0 # gives semantic-release access to all previous commits
token: ${{ secrets.GH_TOKEN }} # admin token
- name: Cache node_modules
uses: actions/cache@v2
uses: actions/cache@v4
env:
cache-name: cache-node-modules
with:
Expand All @@ -28,33 +28,17 @@ jobs:
${{ runner.OS }}-${{ env.cache-name }}-
${{ runner.OS }}-
- name: Setup Node.js
uses: actions/setup-node@v1
uses: actions/setup-node@v4
with:
node-version: 16.15.0
node-version: 20.13.1
- name: Install dependencies
run: yarn
# - name: Compile TS => JS
# run: yarn build
- name: Package code
run: yarn package
# - name: Bundle code
# uses: tool3/ncc@master
# with:
# github_token: ${{ secrets.GH_TOKEN }}
# src: 'src/index.ts'
# branch: 'main'
# ncc_args: '--source-map, --license, licenses.txt'
# - name: Upload artifact
# uses: actions/upload-artifact@v3
# with:
# name: dist
# path: dist/
- name: Commit dist
uses: EndBug/add-and-commit@v9
with:
default_author: github_actions
message: 'Commiting for release'
message: "Commiting for release"
- name: Cut release
run: yarn release
# white space

2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16.15.0
20.13.1
62 changes: 31 additions & 31 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
{
"author": "Mason Goetz <masonlgoetz@gmail.com>",
"dependencies": {
"@actions/core": "^1.8.0",
"@actions/github": "^5.0.1",
"@aws-sdk/client-s3": "^3.58.0",
"@slack/web-api": "^6.7.1",
"date-fns": "^2.28.0",
"@actions/core": "^1.10.1",
"@actions/github": "^6.0.0",
"@aws-sdk/client-s3": "^3.574.0",
"@slack/web-api": "^7.0.4",
"date-fns": "^3.6.0",
"memory-cache": "^0.2.0",
"node-fetch": "^2.6.7",
"winston": "^3.7.2"
"node-fetch": "^3.3.2",
"winston": "^3.13.0"
},
"description": "Notify requested PR reviewers via slack so they actually know that you want them to look at something because people don't check email.",
"devDependencies": {
"@commitlint/cli": "^16.2.4",
"@commitlint/config-conventional": "^16.2.4",
"@semantic-release/changelog": "^6.0.1",
"@semantic-release/commit-analyzer": "^9.0.2",
"@commitlint/cli": "^19.3.0",
"@commitlint/config-conventional": "^19.2.2",
"@semantic-release/changelog": "^6.0.3",
"@semantic-release/commit-analyzer": "^12.0.0",
"@semantic-release/exec": "^6.0.3",
"@semantic-release/git": "^10.0.1",
"@semantic-release/github": "^8.0.4",
"@semantic-release/npm": "^9.0.1",
"@types/memory-cache": "^0.2.2",
"@types/node": "^16.10.5",
"@types/node-fetch": "^2.6.1",
"@typescript-eslint/parser": "^5.8.1",
"@vercel/ncc": "^0.31.1",
"commitizen": "^4.2.3",
"conventional-changelog-conventionalcommits": "^4.6.3",
"eslint": "^8.5.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-prettier": "^4.0.0",
"husky": "^7.0.4",
"jest": "^27.2.5",
"@semantic-release/github": "^10.0.3",
"@semantic-release/npm": "^12.0.1",
"@types/memory-cache": "^0.2.5",
"@types/node": "^20.12.11",
"@types/node-fetch": "^2.6.11",
"@typescript-eslint/parser": "^7.8.0",
"@vercel/ncc": "^0.38.1",
"commitizen": "^4.3.0",
"conventional-changelog-conventionalcommits": "^8.0.0",
"eslint": "^9.2.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-prettier": "^5.1.3",
"husky": "^9.0.11",
"jest": "^29.7.0",
"js-yaml": "^4.1.0",
"lint-staged": "^12.4.1",
"prettier": "^2.5.1",
"semantic-release": "^19.0.2",
"ts-jest": "^27.1.2",
"typescript": "^4.4.4"
"lint-staged": "^15.2.2",
"prettier": "^3.2.5",
"semantic-release": "^23.1.1",
"ts-jest": "^29.1.2",
"typescript": "^5.4.5"
},
"license": "MIT",
"lint-staged": {
Expand Down
8 changes: 4 additions & 4 deletions src/actions/createInitialMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import { fail } from "../utils/fail";
import { getPullRequest } from "../utils/getPullRequest";
import { logger } from "../utils/logger";
import { slackWebClient } from "../utils/slackWebClient";
import { getRequestedReviewersAsIndividuals } from "../utils/getRequestedReviewersAsIndividuals";

export const createInitialMessage = async (): Promise<string | void> => {
const verbose: boolean = core.getBooleanInput("verbose");
logger.info(`START createInitialMessage. Verbose? ${verbose}`)
logger.info(`START createInitialMessage. Verbose? ${verbose}`);

try {
const channelId = core.getInput("channel-id");
Expand All @@ -17,7 +18,6 @@ export const createInitialMessage = async (): Promise<string | void> => {

if (!pull_request || !repository) return;

const requestedReviewers = pull_request.requested_reviewers ? pull_request.requested_reviewers.map((user: any) => user.login) : [];
const requestedReviewers = await getRequestedReviewersAsIndividuals();

//
Expand Down Expand Up @@ -63,10 +63,10 @@ export const createInitialMessage = async (): Promise<string | void> => {
owner: repository.owner.login,
repo: repository.name,
issue_number: pull_request.number,
body: slackMessageId
body: slackMessageId,
});

logger.info(`END createInitialMessage: ${slackMessageId}`)
logger.info(`END createInitialMessage: ${slackMessageId}`);
return slackMessageId;
} catch (error: any) {
console.error("error in createInitialMessage::: ", error);
Expand Down
8 changes: 5 additions & 3 deletions src/actions/handleCommitPush.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { slackWebClient } from "../utils/slackWebClient";
// NOTE in the future we may want to wait to notify everyone that they can review it again when the PR author
// explicitly asks for a re-review
export const handleCommitPush = async (): Promise<void> => {
logger.info('START handleCommitPush')
logger.info("START handleCommitPush");
try {
const channelId = core.getInput("channel-id");
const { repository } = github.context.payload;
Expand Down Expand Up @@ -56,7 +56,9 @@ export const handleCommitPush = async (): Promise<void> => {
const previousReviewers = res.data.map((review) => review!.user!.login);
const distinctPreviousReviewers = [...new Set(previousReviewers)];
const baseMessage = `new code has been committed since your review of <${pull_request._links.html.href}|*PR ${pull_request.number}*>, please review the updates.`;
const usersToAtString = await createUsersToAtString(distinctPreviousReviewers);
const usersToAtString = await createUsersToAtString(
distinctPreviousReviewers
);
const text = `${usersToAtString} ${baseMessage}`;
const threadUpdateRes = await slackWebClient.chat.postMessage({
channel: channelId,
Expand All @@ -78,7 +80,7 @@ export const handleCommitPush = async (): Promise<void> => {
}
}

logger.info('END handleCommitPush')
logger.info("END handleCommitPush");
return;
} catch (error) {
fail(error);
Expand Down
4 changes: 2 additions & 2 deletions src/actions/handleLabelChange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { slackWebClient } from "../utils/slackWebClient";

// TODO handle labels being removed
export const handleLabelChange = async (): Promise<void> => {
logger.info('START handleLableChange')
logger.info("START handleLableChange");
try {
const channelId = core.getInput("channel-id");
const labelNameToWatchFor = core.getInput("label-name-to-watch-for");
Expand Down Expand Up @@ -67,7 +67,7 @@ export const handleLabelChange = async (): Promise<void> => {
name: "heart_eyes",
});

logger.info('END handleLableChange')
logger.info("END handleLableChange");
return;
} catch (error) {
fail(error);
Expand Down
4 changes: 2 additions & 2 deletions src/actions/handleMerge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { slackWebClient } from "../utils/slackWebClient";
// will only run on push to base branch (i.e. staging), so we can assume that a closed state for PR
// equates to 'merged' (no specific event for 'merged' on PRs)
export const handleMerge = async (): Promise<void> => {
logger.info('START handleMerge')
logger.info("START handleMerge");
try {
const channelId = core.getInput("channel-id");
const { commits, repository } = github.context.payload;
Expand Down Expand Up @@ -55,7 +55,7 @@ export const handleMerge = async (): Promise<void> => {
text,
});

logger.info('END handleMerge')
logger.info("END handleMerge");
return;
} catch (error) {
fail(error);
Expand Down
8 changes: 4 additions & 4 deletions src/actions/handlePullRequestReview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const reactionMap = {
};

export const handlePullRequestReview = async (): Promise<void> => {
logger.info('START handlePullRequestReview')
logger.info("START handlePullRequestReview");
try {
const channelId = core.getInput("channel-id");
const slackUsers = await getEngineersFromS3();
Expand Down Expand Up @@ -119,7 +119,7 @@ export const handlePullRequestReview = async (): Promise<void> => {
}

if (hasReaction) {
logger.info('END handlePullRequestReview: hasReaction')
logger.info("END handlePullRequestReview: hasReaction");
return;
}

Expand All @@ -130,8 +130,8 @@ export const handlePullRequestReview = async (): Promise<void> => {
name: reactionToAdd,
});

logger.info('END handlePullRequestReview: new reactions added')
return
logger.info("END handlePullRequestReview: new reactions added");
return;
} catch (error) {
fail(error);
throw error;
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { handlePullRequestReview } from "./actions/handlePullRequestReview";
import { logger } from "./utils/logger";

const run = async (): Promise<void> => {
logger.info(`START run (github.context): ${JSON.stringify(github.context)}`)
logger.info(`START run (github.context): ${JSON.stringify(github.context)}`);
const { eventName, payload, ref } = github.context;
const baseBranch = core.getInput("base-branch");
const isActingOnBaseBranch = ref.includes(baseBranch);
Expand Down
4 changes: 2 additions & 2 deletions src/utils/createUsersToAtString.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { logger } from "./logger";
export const createUsersToAtString = async (
reviewers: string[]
): Promise<string> => {
logger.info('START createUsersToAtString')
logger.info("START createUsersToAtString");
let engineers: EngineerGithubSlackMapping[] = [];
try {
const res = await getEngineersFromS3();
Expand All @@ -31,6 +31,6 @@ export const createUsersToAtString = async (
return;
});

logger.info(`END createUsersToAtString: ${JSON.stringify(usersToAtString)}`)
logger.info(`END createUsersToAtString: ${JSON.stringify(usersToAtString)}`);
return usersToAtString;
};
2 changes: 1 addition & 1 deletion src/utils/fail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { logger } from "./logger";

export const fail = (error: any) => {
const failSilently = core.getInput("fail-silently");
logger.error(JSON.stringify(error))
logger.error(JSON.stringify(error));
if (failSilently === "true") {
core.warning(error.message ?? "Oops");
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/getEngineersFromS3/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const getEngineersFromS3 = (): Promise<{
engineers: EngineerGithubSlackMapping[];
}> => {
return new Promise(async (resolve, reject) => {
logger.info('START getEngineersFromS3')
logger.info("START getEngineersFromS3");
// required for this to work
const Bucket = core.getInput("aws-s3-bucket");
const Key = core.getInput("aws-s3-object-key");
Expand Down
23 changes: 13 additions & 10 deletions src/utils/getPullRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,26 @@ import * as github from "@actions/github";
import { fail } from "./fail";
import { logger } from "./logger";


export const getPullRequest = async () => {
logger.info('START getPullRequest')
logger.info("START getPullRequest");
try {
const ghToken = core.getInput("github-token");
const octokit = github.getOctokit(ghToken);
const { commits, pull_request: prFromContext, repository } = github.context.payload;
const {
commits,
pull_request: prFromContext,
repository,
} = github.context.payload;

if (prFromContext) {
logger.info(`using PR from context: ${JSON.stringify(prFromContext)}`)
logger.info(`using PR from context: ${JSON.stringify(prFromContext)}`);
const { data } = await octokit.rest.pulls.get({
owner: github.context.payload.repository?.owner.login || '',
repo: repository?.name || '',
pull_number: prFromContext.number
})
owner: github.context.payload.repository?.owner.login || "",
repo: repository?.name || "",
pull_number: prFromContext.number,
});
return data;
}
}

if (!commits || !commits.length) {
throw Error("No commits found");
Expand All @@ -43,7 +46,7 @@ export const getPullRequest = async () => {
throw Error(`No pull_request found for commit: ${commit_sha}`);
}

logger.info(`END getPullRequest: ${JSON.stringify(pull_request)}`)
logger.info(`END getPullRequest: ${JSON.stringify(pull_request)}`);
return pull_request;
} catch (error) {
fail(error);
Expand Down
Loading

0 comments on commit a713396

Please sign in to comment.