Skip to content

Commit

Permalink
feat: complete module and cli
Browse files Browse the repository at this point in the history
  • Loading branch information
maximousblk authored Feb 6, 2021
1 parent eabc15e commit e500eb9
Show file tree
Hide file tree
Showing 12 changed files with 381 additions and 497 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 Maximous Black
Copyright (c) 2021 Maximous Black

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
103 changes: 12 additions & 91 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,110 +13,31 @@ deno install -A https://deno.land/x/ghlog/ghlog.ts
## Usage

```sh
ghlog <owner/repo> [ ...arguments ] [ ...options ]
ghlog <user/repo> [ ...arguments ] [ ...options ]
```

#### Arguments

| argument | description |
| ------------- | ---------------------------------------------------------------------- |
| `[start_tag]` | where to start counting changes. Defaults to last tag or first commit. |
| `[end_tag]` | where to stop counting changes. Defaults to the last commit. |
| argument | description |
| ------------ | ------------------------------------------------------------------------ |
| `[base_ref]` | where to start counting changes. Defaults to last tag or initial commit. |
| `[head_ref]` | where to stop counting changes. Defaults to the latest commit. |

#### Options

| option | description |
| ---------------- | -------------------------------------------------------------------------------------- |
| `-t, --template` | location of the release notes template (default: undefined) |
| `-o, --output` | location where to output generated release notes (default: undefined) |
| `-v, --version` | version to use in release notes (default: "UNRELEASED") |
| `-b, --branch` | name of the default branch of the repo (default: "master") |
| `-m, --markdown` | use CommonMark spec instead of GitHub Flavoured Markdown |
| `-a, --append` | append the out to an existing changelog instead of owerwriting it |
| `--auth` | GitHub access token. Use this to avoid API rate limits and access private repositories |
| option | description |
| --------------- | ----------------------------------------------------------------- |
| `-h, --help` | show help |
| `-o, --output` | location where to output release notes (default: `CHANGELOG.md`) |
| `-v, --version` | version to use in release notes (default: "UNRELEASED") |
| `--auth` | Use this to avoid API rate limits and access private repositories |

You can also use the `GITHUB_TOKEN` environment variable to use the GitHub
access token.

## Templates

ghlog can use any plaintext file for templates. Just use appropriate tags where
you need them. If you don't define a template, ghlog cli will output only a
markdown list of changes.

Default tags:

- `{{ VERSION }}` - release version
- `{{ CHANGELOG }}` - list of changes

Example :

```md
<!-- template.md -->

### {{ VERSION }}

{{ CHANGELOG }}
```

```sh
# /bin/sh
ghlog denoland/deno -v 1.3.3 -t template.md -o changelog.md
```

```md
<!-- changelog.md -->

### 1.3.3

- docs(std/fs): remove stale references to readFileStr and writeFileStr (#7254)
- Typo in zsh env setup steps (#7250)
- upgrade: rust 1.46.0 (#7251)
```

### Plugins

In addition to using the CLI, you can build custom plugins for ghlog.

Official plugins:

- [Version](plugins/Version.ts) - Set the release version. tag: `{{ VERSION }}`
- [SetDate](plugins/SetDate.ts) - Set date of release in desired format. tag:
`{{ DATE }}`
- [CodeName](plugins/CodeName.ts) - Set a code name for the release. tag:
`{{ CODENAME }}`

View [plugins](plugins) and
[docs](https://doc.deno.land/https/deno.land/x/ghlog/mod.ts) for more info.

Example:

```ts
// release.ts
import ghlog from "https://deno.land/x/ghlog/mod.ts";
import "https://deno.land/x/ghlog/plugins/SetDate.ts";
import "https://deno.land/x/ghlog/plugins/Version.ts";

const template: string = `
# {{ VERSION }} / {{ DATE }}
{{ CHANGELOG }}
`;

const changelog: string = (await ghlog(template, "denoland/deno"))
.ghlogSetDate().ghlogVersion("1.3.3");

console.log(changelog);

/*
$ deno run -A release.ts
### 1.3.3 / 02 09 2020
- docs(std/fs): remove stale references to readFileStr and writeFileStr (#7254)
- Typo in zsh env setup steps (#7250)
- upgrade: rust 1.46.0 (#7251)
*/
```
ghlog provides a default template out of the box, but if you want more custom template, you can use [`mod.ts`](./mod.ts) as a reference and create your own templates.

## License

Expand Down
37 changes: 37 additions & 0 deletions ghlog.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { formatTime, parseFlags } from "./src/deps.ts";
import { defaultChangelog } from "./mod.ts";

const args = parseFlags(Deno.args);

if (args.h || args.help) {
console.log(`
ghlog - Generate release notes based on GitHub commits
Usage:
ghlog <owner/repo> [base_ref] [head_ref] [options]
Options:
-h, --help - this help menu
-o, --output <path> - location of changelog output (default: CHANGELOG.md)
-v, --version <version> - release version
--auth <token> - GitHub access token
`);
Deno.exit(0);
}

const repo = String(args._[0]);
const base = args._[1] ? String(args._[1]) : undefined;
const head = args._[2] ? String(args._[2]) : undefined;

const output: string = args.o ?? args.output;
const version: string = args.v ?? args.version ?? "UNRELEASED";

const myChangelog = await defaultChangelog(
{ name: repo, base, head },
{
name: version,
tag: version,
date: formatTime(new Date(), "dd.MM.yyyy"),
},
);

Deno.writeTextFile(output ?? "CHANGELOG.md", myChangelog);
Loading

0 comments on commit e500eb9

Please sign in to comment.