Skip to content

Commit

Permalink
Add import maps and import standard library from jsr (#134)
Browse files Browse the repository at this point in the history
- Add deno.json with import maps
- Load the standard library from jsr as that seems [recommended nowadays](https://docs.deno.com/runtime/manual/basics/import_maps/#example---using-the-deno-standard-library) and I find it more managable than to have versions in each file.
- Bump standard library from 0.189.0 to 0.196.0 because that is the oldest version available on jsr.
  • Loading branch information
silverwind authored Jul 13, 2024
1 parent f80155a commit 65c2402
Show file tree
Hide file tree
Showing 14 changed files with 180 additions and 52 deletions.
6 changes: 3 additions & 3 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
**

!src
.git
.github
.vscode
2 changes: 1 addition & 1 deletion .github/workflows/deploy-to-fly.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
name: Deploy proxy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: superfly/flyctl-actions/setup-flyctl@master
- run: flyctl deploy --remote-only
env:
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ RUN apt-get update && apt-get install -y git
EXPOSE 8000
USER deno
WORKDIR /app
COPY src .
RUN deno cache webhook.ts
CMD ["run", "--allow-net", "--allow-env", "--allow-run", "--allow-sys", "webhook.ts"]
COPY . .
RUN deno cache src/webhook.ts
CMD ["run", "--allow-net", "--allow-env", "--allow-run", "--allow-sys", "src/webhook.ts"]
11 changes: 11 additions & 0 deletions deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"imports": {
"@octokit/types": "npm:@octokit/[email protected]",
"@octokit/webhooks": "npm:@octokit/[email protected]",
"@octokit/webhooks-methods": "npm:@octokit/[email protected]",
"@std/async": "jsr:@std/[email protected]",
"@std/http": "jsr:@std/[email protected]",
"@std/semver": "jsr:@std/[email protected]",
"@std/testing": "jsr:@std/[email protected]"
}
}
172 changes: 147 additions & 25 deletions deno.lock

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

4 changes: 2 additions & 2 deletions src/giteaVersion.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { SemVer } from "https://deno.land/[email protected]/semver/mod.ts";
import { parse } from "@std/semver";
import { getMilestones } from "./github.ts";

export class GiteaVersion {
majorMinorVersion: string;
milestoneNumber: number;

constructor(milestone: { title: string; number: number }) {
const semver = new SemVer(milestone.title);
const semver = parse(milestone.title);
this.majorMinorVersion = `${semver.major}.${semver.minor}`;
this.milestoneNumber = milestone.number;
}
Expand Down
10 changes: 4 additions & 6 deletions src/github.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as semver from "https://deno.land/[email protected]/semver/mod.ts";
import { lt, parse, valid } from "@std/semver";
import { getPrBranchName } from "./git.ts";
import { GiteaVersion } from "./giteaVersion.ts";
import { backportPrExistsCache } from "./state.ts";
Expand Down Expand Up @@ -293,18 +293,16 @@ export const getMilestones = async (): Promise<Milestone[]> => {
);
if (!response.ok) throw new Error(await response.text());
const json = await response.json();
const milestones: Milestone[] = json.filter((m: Milestone) =>
semver.valid(m.title)
);
const milestones: Milestone[] = json.filter((m: Milestone) => valid(m.title));

// take only the earliest patch version of each minor version (e.g. 1.19.0, 1.19.1, 1.19.2 -> 1.19.0)
const earliestPatchVersions: Record<string, Milestone> = {};
for (const milestone of milestones) {
const version = new semver.SemVer(milestone.title);
const version = parse(milestone.title);
const key = `${version.major}.${version.minor}`;
if (
!earliestPatchVersions[key] ||
semver.lt(milestone.title, earliestPatchVersions[key].title)
lt(milestone.title, earliestPatchVersions[key].title)
) {
earliestPatchVersions[key] = milestone;
}
Expand Down
5 changes: 1 addition & 4 deletions src/github_test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import {
assertEquals,
assertFalse,
} from "https://deno.land/[email protected]/testing/asserts.ts";
import { assertEquals, assertFalse } from "@std/testing/asserts";
import {
backportPrExists,
fetchBranch,
Expand Down
2 changes: 1 addition & 1 deletion src/labels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
removeLabel,
} from "./github.ts";
import { fetchGiteaVersions } from "./giteaVersion.ts";
import { debounce } from "https://deno.land/[email protected]/async/mod.ts";
import { debounce } from "@std/async";
import type { PullRequest } from "./types.ts";

// a relevant label is one that is used to control the merge queue,
Expand Down
2 changes: 1 addition & 1 deletion src/mergeQueue.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { fetchPendingMerge, removeLabel } from "./github.ts";
import * as prActions from "./prActions.ts";
import { debounce } from "https://deno.land/[email protected]/async/mod.ts";
import { debounce } from "@std/async";

const updateBranch = async () => {
// fetch all PRs that are pending merge
Expand Down
2 changes: 1 addition & 1 deletion src/milestones.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as SemVer from "https://deno.land/[email protected]/semver/mod.ts";
import * as SemVer from "@std/semver";
import { fetchGiteaVersions } from "./giteaVersion.ts";
import * as github from "./github.ts";
import type { PullRequest } from "./types.ts";
Expand Down
2 changes: 1 addition & 1 deletion src/prActions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { addComment, needsUpdate, removeLabel, updatePr } from "./github.ts";
import { debounce } from "https://deno.land/[email protected]/async/mod.ts";
import { debounce } from "@std/async";

const execute = async (
label: string,
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Endpoints } from "npm:@octokit/types@13.5.0";
import { Endpoints } from "@octokit/types";

type IssueGetResponse =
Endpoints["GET /repos/{owner}/{repo}/issues/{issue_number}"]["response"][
Expand Down
6 changes: 3 additions & 3 deletions src/webhook.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { serve } from "https://deno.land/[email protected]/http/server.ts";
import { createEventHandler } from "https://esm.sh/@octokit/webhooks@11.0.0";
import { verify } from "https://esm.sh/@octokit/webhooks-methods@3.0.2";
import { serve } from "@std/http";
import { createEventHandler } from "@octokit/webhooks";
import { verify } from "@octokit/webhooks-methods";
import * as backport from "./backport.ts";
import * as labels from "./labels.ts";
import * as mergeQueue from "./mergeQueue.ts";
Expand Down

0 comments on commit 65c2402

Please sign in to comment.