Skip to content

Commit

Permalink
Run typecheck on CI and fix issues (#133)
Browse files Browse the repository at this point in the history
1. type checking (`deno check`) was not running on CI and there were 7 type errors which I've fixed and now it's running
2. GitHub API types are sourced from https://github.com/octokit/types.ts and I created basic types for `Issue` and `PullRequest`.
3. IDK about those two webhook errors, so I used `@ts-expect-error`.
4. `deno.lock` was auto generated, I guess it's good to have it in-repo. 
5. `actions/checkout` is upgraded to latest major.
  • Loading branch information
silverwind authored Jul 13, 2024
1 parent 8cea624 commit f80155a
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 22 deletions.
20 changes: 6 additions & 14 deletions .github/workflows/deno.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,12 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Setup repo
uses: actions/checkout@v3

- name: Setup Deno
uses: denoland/setup-deno@v1

- name: Verify formatting
run: deno fmt --check

- name: Run linter
run: deno lint

- name: Run tests
run: deno test -A
- uses: actions/checkout@v4
- uses: denoland/setup-deno@v1
- run: deno fmt --check
- run: deno lint
- run: shopt -s globstar; deno check src/**/*.ts
- run: deno test -A
env:
BACKPORTER_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BACKPORTER_GITEA_FORK: GiteaBot/gitea
Expand Down
31 changes: 31 additions & 0 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/backport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
fetchCurrentUser,
fetchPr,
} from "./github.ts";
import type { Issue } from "./types.ts";

if (
!Deno.env.get("BACKPORTER_GITEA_FORK") ||
Expand All @@ -32,7 +33,7 @@ export const run = async () => {
}
};

const parseCandidate = async (candidate, giteaVersion: GiteaVersion) => {
const parseCandidate = async (candidate: Issue, giteaVersion: GiteaVersion) => {
if (await backportPrExists(candidate, giteaVersion.majorMinorVersion)) {
console.log(`Backport PR already exists for #${candidate.number}`);
return;
Expand Down
9 changes: 3 additions & 6 deletions src/labels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from "./github.ts";
import { fetchGiteaVersions } from "./giteaVersion.ts";
import { debounce } from "https://deno.land/[email protected]/async/mod.ts";
import type { PullRequest } from "./types.ts";

// a relevant label is one that is used to control the merge queue,
// manage backports or any other label that causes the bot to act on
Expand Down Expand Up @@ -77,15 +78,11 @@ export const removeBackportLabelsFromPrsTargetingReleaseBranches = async () => {
};

// given a list of PRs, removes the backport/* labels from them
export const removeBackportLabelsFromPrs = (prs) => {
export const removeBackportLabelsFromPrs = (prs: PullRequest[]) => {
if (prs === undefined) {
throw new Error("removeBackportLabelsFromPrs called with undefined");
}
return Promise.all(prs.flatMap((pr: {
title;
labels;
number: number;
}) => {
return Promise.all(prs.flatMap((pr: PullRequest) => {
const backportLabels = pr.labels.filter((label: { name: string }) =>
label.name.startsWith("backport/")
);
Expand Down
3 changes: 2 additions & 1 deletion src/milestones.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as SemVer from "https://deno.land/[email protected]/semver/mod.ts";
import { fetchGiteaVersions } from "./giteaVersion.ts";
import * as github from "./github.ts";
import type { PullRequest } from "./types.ts";

// given a PR number, set the milestone of the PR according to its base branch
export const assign = async (pr: { number: number; base: { ref: string } }) => {
Expand Down Expand Up @@ -58,7 +59,7 @@ const removeMilestonesFromUnmergedClosedPrs = async () => {
// and remove the milestone each PR
return Promise.all(milestones.flatMap(async (m) => {
const prs = await github.fetchUnmergedClosedWithMilestone(m.title);
return prs.items.map(async (pr) => {
return prs.items.map(async (pr: PullRequest) => {
const response = await github.removeMilestone(pr.number);
if (!response.ok) {
console.error(
Expand Down
13 changes: 13 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Endpoints } from "npm:@octokit/[email protected]";

type IssueGetResponse =
Endpoints["GET /repos/{owner}/{repo}/issues/{issue_number}"]["response"][
"data"
];
type PullGetResponse =
Endpoints["GET /repos/{owner}/{repo}/pulls/{pull_number}"]["response"][
"data"
];

export type Issue = IssueGetResponse;
export type PullRequest = PullGetResponse;
2 changes: 2 additions & 0 deletions src/webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ webhook.on(
"pull_request_review",
],
({ payload }) => {
// @ts-expect-error -- unknown
lgtm.setPrStatusAndLabel(payload.pull_request);
},
);
Expand Down Expand Up @@ -128,6 +129,7 @@ serve(async (req: Request) => {
status: 400,
});
}
// @ts-expect-error -- unknown
webhook.receive({ id, name, payload: JSON.parse(requestBody) });

return Response.json({ message: "Webhook received" });
Expand Down

0 comments on commit f80155a

Please sign in to comment.