Skip to content

Commit

Permalink
feat: Use last n releases (#62)
Browse files Browse the repository at this point in the history
* feat: add use last n releases option

* doc: update readme

* feat: add graphql query

* refactor: change last n release query

* feat: add last n releases query
  • Loading branch information
adrianiy committed Oct 22, 2021
1 parent dc326d3 commit 45eee85
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 26 deletions.
57 changes: 33 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ We support `.yml` and `.json` formats with these options:
| message | `chore: update RELEASE-NOTES` | Commit message |
| filter | `is:closed` | Filter applied on pull request query |
| branch | `main` | Branch where output will be uploaded |
| useLast | `null` | Uses last `n` releases in generation step |
| title | `RELEASE NOTES` | Title used in output markdown |
| decoration | [Decoration object](#decoration-object) | Icon decoration for each issue type |
| webhooks | `{}` | List of [webhooks](#webhooks) to execute |
Expand Down Expand Up @@ -172,20 +173,23 @@ There are two available commands `generate` and `publish`.
Generates Release Note markdown

Opciones:
--version Show version number [boolean]
--help Show help [boolean]
-c, --configuration Configuration file path [string]
-o, --output, --out Output path [string]
-n, --name Output file name [string]
-a, --auth Manual creadentials input [boolean]
-r, --repo Repo in format user/repo [string]
-f, --filter Filter to apply in Pull request query [string]
-s, --since Start date in pull request filter query [string]
-m, --message Commit message [string]
-p, --publish Publish output to your repo [boolean]
--assets File to upload in publish process [string]
-v, --verbose Makes the script verbose [boolean]
-i, --interactive Executes interactive version of the script [boolean]
--version Muestra número de versión [booleano]
--help Muestra ayuda [booleano]
-c, --configuration Configuration file path [cadena de caracteres]
-o, --output, --out Output path [cadena de caracteres]
-n, --name Output file name [cadena de caracteres]
-a, --auth Manual creadentials input [booleano]
-r, --repo Repo in format user/repo [cadena de caracteres]
-f, --filter Filter to apply in Pull request query
[cadena de caracteres]
-s, --since Start date in pull request filter query
[cadena de caracteres]
-u, --use, --useLast Uses last n releases [número]
-m, --message Commit message [cadena de caracteres]
-p, --publish Publish output to your repo [booleano]
--assets File to upload in publish process [cadena de caracteres]
-v, --verbose Makes the script verbose [booleano]
-i, --interactive Executes interactive version of the script [booleano]
```

###### Publish
Expand All @@ -196,16 +200,21 @@ Opciones:
Pubish Release Note in your repo

Opciones:
--version Muestra número de versión [booleano]
--help Muestra ayuda [booleano]
-c, --configuration Configuration file path [cadena de caracteres]
-a, --auth Manual creadentials input [booleano]
-r, --repo Repo in format user/repo [cadena de caracteres]
-m, --message Commit message [cadena de caracteres]
-p, --publish Publish output to your repo [booleano]
--assets File to upload in publish process [cadena de caracteres]
-v, --verbose Makes the script verbose [booleano]
-i, --interactive Executes interactive version of the script [booleano]
--version Muestra número de versión [booleano]
--help Muestra ayuda [booleano]
-c, --configuration Configuration file path [cadena de caracteres]
-a, --auth Manual creadentials input [booleano]
-r, --repo Repo in format user/repo [cadena de caracteres]
-f, --filter Filter to apply in Pull request query
[cadena de caracteres]
-s, --since Start date in pull request filter query
[cadena de caracteres]
-u, --use, --useLast Uses last n releases [número]
-m, --message Commit message [cadena de caracteres]
-p, --publish Publish output to your repo [booleano]
--assets File to upload in publish process [cadena de caracteres]
-v, --verbose Makes the script verbose [booleano]
-i, --interactive Executes interactive version of the script [booleano]
```


Expand Down
5 changes: 5 additions & 0 deletions src/commander/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ export const repoOptions: Record<string, Options> = {
type: 'string',
description: 'Start date in pull request filter query',
},
use: {
alias: ['u', 'useLast'],
type: 'number',
description: 'Uses last n releases',
},
message: {
alias: 'm',
type: 'string',
Expand Down
2 changes: 2 additions & 0 deletions src/configuration/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export interface Configuration {
filter?: string;
// Start date in pull request filter query
since?: string;
// Use last n releases
useLast?: number;
// Split Release-Notes on file per Relase
// This option will create a folder in `out` dir.
split?: boolean;
Expand Down
32 changes: 30 additions & 2 deletions src/connector/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import { Octokit } from 'octokit';
import { Configuration } from 'configuration/configuration';
import { GraphQlQueryResponseData } from '@octokit/graphql/dist-types/types';
import { LabelNode, PullRequest, PullRequestResponse } from './models/pullRequest';
import { Release } from './models/release';
import { Release, ReleaseNode } from './models/release';
import { gitHubConnection } from 'connections/github';
import { CliParams } from 'commander/options';
import prQuery from './queries/pull_requests.graphql';
import releaseQuery from './queries/latest_release.graphql';
import lastNReleasesQuery from './queries/last_n_releases.graphql';
import log4js from 'log4js';
import fs from 'fs';
import path from 'path';
Expand Down Expand Up @@ -48,6 +49,11 @@ export class GitHubConnector extends Connector {
return { createdAt: this._configuration.since, tagName: 'mock' };
}

console.log(this._configuration.useLast);
if (this._configuration.useLast) {
return await this._getLatestNReleases();
}

this._verbose && logger.info('Getting latest release...');

const query = releaseQuery.loc!.source.body;
Expand All @@ -59,7 +65,7 @@ export class GitHubConnector extends Connector {

const latestRelease: Release = data.repository?.latestRelease;

this._verbose && logger.info(`Latest release date is ${latestRelease?.createdAt}`);
this._verbose && logger.info(`Latest release ${latestRelease?.tagName} date is ${latestRelease?.createdAt}`);

return latestRelease;
}
Expand Down Expand Up @@ -108,6 +114,28 @@ export class GitHubConnector extends Connector {
super._setRepoData(repository || process.env.GITHUB_REPOSITORY!);
}

private async _getLatestNReleases(): Promise<Release> {
this._verbose && logger.info(`Getting latest ${this._configuration.useLast} releases...`);

const query = lastNReleasesQuery.loc!.source.body;

const data = (await this._connection.graphql(query, {
owner: this._owner,
name: this._repo,
last: this._configuration.useLast,
})) as GraphQlQueryResponseData;

const releases: ReleaseNode = data.repository?.releases;

this._verbose && logger.info(`We've found ${releases.nodes.length} releases!`);

const latestRelease: Release = releases.nodes[0];

this._verbose && logger.info(`Latest release ${latestRelease?.tagName} date is ${latestRelease?.createdAt}`);

return latestRelease;
}

private _getLabelFilter(): string {
const { labels, ignoredLabels } = this._configuration;

Expand Down
4 changes: 4 additions & 0 deletions src/connector/models/release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@ export interface Release {
createdAt: string;
tagName: string;
}

export interface ReleaseNode {
nodes: Release[];
}
10 changes: 10 additions & 0 deletions src/connector/queries/last_n_releases.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
query SkipRelease($owner: String!, $name: String!, $last: Int!) {
repository(owner: $owner, name: $name) {
releases(last: $last) {
nodes {
tagName
createdAt
}
}
}
}

0 comments on commit 45eee85

Please sign in to comment.