Skip to content

Commit

Permalink
Revert ":sparkles: Add match option"
Browse files Browse the repository at this point in the history
This reverts commit f3aefac.
  • Loading branch information
proudust committed Jul 17, 2022
1 parent 1b40960 commit 0ffe4f5
Show file tree
Hide file tree
Showing 5 changed files with 193 additions and 1,843 deletions.
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@ behavior.
All inputs are optional. If not set, sensible defaults will be used.
| Name | Description | Default |
| ---------- | --------------------------------------------------- | --------------------------------------------------------- |
| token | Personal Access Token (PAT) | `GITHUB_TOKEN` |
| repo | Target repository | The owner and repository that triggered the workflow run. |
| commit-ish | Commit-ish object names to describe. | The branch or tag ref that triggered the workflow run. |
| match | Only consider tags matching the given glob pattern. | All tags |
| default | Use this value if the name is not found. | `​` |
| Name | Description | Default |
| ---------- | ---------------------------------------- | --------------------------------------------------------- |
| token | Personal Access Token (PAT) | `GITHUB_TOKEN` |
| repo | Target repository | The owner and repository that triggered the workflow run. |
| commit-ish | Commit-ish object names to describe. | The branch or tag ref that triggered the workflow run. |
| default | Use this value if the name is not found. | `​` |

### Action outputs

Expand Down
10 changes: 6 additions & 4 deletions cli/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,26 @@ async function version(): Promise<string> {
}
}

type CommandOptions = { repo?: string; default?: string };
type CommandArguments = [commitIsh: string | undefined];

async function run() {
return await new Command()
return await new Command<CommandOptions, CommandArguments>()
.name("gh-describe")
.version(globalThis.version || await version())
.description("Emulate `git describe --tags` in shallow clone repository.")
.option("-R, --repo <repo>", "Target repository. Format: OWNER/REPO")
.option("--match <grob:string>", "Only consider tags matching the given glob pattern.")
.option("--default <tag:string>", "Use this value if the name is not found.")
.type("runtime", new EnumType(["deno", "node"]))
.option(
"--runtime <runtime:runtime>",
"If installed by `gh extension install`, can specify the execution runtime.",
)
.arguments("[commit-ish]")
.action(async ({ repo, default: defaultTag, match }, commitish) => {
.action(async ({ repo, default: defaultTag }, commitish) => {
try {
await Deno.permissions.request({ name: "run", command: "gh" });
const { describe } = await ghDescribe(repo, commitish, defaultTag, match);
const { describe } = await ghDescribe(repo, commitish, defaultTag);
console.log(describe);
} catch (e: unknown) {
if (e instanceof GhDescribeError) {
Expand Down
13 changes: 3 additions & 10 deletions core/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@ export async function ghDescribe(
repo?: string | Repo,
commitish?: string,
defaultValue?: string,
match?: string,
): Promise<GhDescribeOutput> {
repo = await resolveRepo(repo);

const [tags, sha] = await Promise.all([fetchTags(repo, match), fetchSha(repo, commitish)]);
const [tags, sha] = await Promise.all([fetchTags(repo), fetchSha(repo, commitish)]);

if (0 < tags.size) {
let distance = 0;
Expand Down Expand Up @@ -70,12 +69,7 @@ export async function resolveRepo(repo?: string | Repo): Promise<Repo> {
}
}

export async function fetchTags(
{ owner, name, host }: Repo,
match?: string,
): Promise<Map<string, string>> {
const matchRegExp = match && globToRegExp(match) || undefined;

export async function fetchTags({ owner, name, host }: Repo): Promise<Map<string, string>> {
const tags: [sha: string, name: string][] = [];
const perPage = 100;
const jq = ".[] | [.commit.sha, .name]";
Expand All @@ -88,8 +82,7 @@ export async function fetchTags(
...stdout
.split("\n")
.filter((x) => !!x)
.map((x) => JSON.parse(x))
.filter((x) => !matchRegExp || matchRegExp.test(x[1])),
.map((x) => JSON.parse(x)),
);
} while (count === perPage);
return new Map(tags);
Expand Down
Loading

0 comments on commit 0ffe4f5

Please sign in to comment.