Skip to content

Commit

Permalink
Add a test, actually filter on groups
Browse files Browse the repository at this point in the history
  • Loading branch information
robotgryphon committed Jan 28, 2024
1 parent a5e8f22 commit 38bc3f9
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,5 @@ Thumbs.db

# Ignore built ts files
__tests__/runner/*
lib/**/*
lib/**/*
packages.json
8 changes: 4 additions & 4 deletions src/github.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { graphql } from "@octokit/graphql";
import { readFile } from "fs/promises";

const query = `query getPackageInfo($org: String!, $repo: String!, $filter: [String]) {
const query = `query getPackageInfo($org: String!, $repo: String!, $nameFilter: [String]) {
repository(owner: $org, name: $repo) {
packages(first: 1, names: $filter) {
packages(first: 1, names: $nameFilter) {
nodes {
latestVersion {
version
Expand Down Expand Up @@ -36,11 +36,11 @@ export interface GHPackage {
}

export class GithubPackages {
public static async getPackageInfo(org: string, repo: string, groups: string[]): Promise<GHPackageInfo> {
public static async getPackageInfo(org: string, repo: string, names: string[]): Promise<GHPackageInfo> {
const getPackageInfo = await graphql<any>(query, {
org: org,
repo: repo,
group: groups,
nameFilter: names,
headers: {
authorization: `bearer ${process.env.GQL_TOKEN}`
}
Expand Down
27 changes: 27 additions & 0 deletions test/test.manual-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

import { config as loadEnv } from "dotenv";
import { readFile, writeFile } from "fs/promises";
import { GithubPackages } from "../src/github";

loadEnv();

const matchFileFilters: Array<RegExp> = [
new RegExp("^compactmachines-(?:[\\d\\.]+){4}.jar$")
];

async function run() {
let pkg = await GithubPackages.getPackageInfo("compactmods", "compactmachines", ["dev.compactmods.compactmachines"]);

console.debug("Latest Version: " + pkg.version);

let matched = matchFileFilters.length == 0 ? pkg.files : pkg.files.filter(file => {
return matchFileFilters.some(filter => {
let matched = filter.test(file.name);
return matched;
});
});

await writeFile("packages.json", JSON.stringify(matched, undefined, 4));
}

run();

0 comments on commit 38bc3f9

Please sign in to comment.