Skip to content

Commit dc15214

Browse files
DovetailJohnjk1z
authored andcommitted
Allow issues to be pulled xx seconds after the commit (#13)
* allow seconds to be specified when searching for closed issues * fix typo * updates to use moment for the Date math * a little code cleanup
1 parent 3d1a512 commit dc15214

File tree

3 files changed

+54
-3
lines changed

3 files changed

+54
-3
lines changed

README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,43 @@ docker container run -e GITLAB_PERSONAL_TOKEN=gitlabSampleToken -e GITLAB_PROJEC
5454
Reference gitlab repo: [generator test](https://gitlab.com/jackzhang/generator-test)
5555

5656

57+
## Options
58+
59+
These can be specified using environment variables
60+
61+
* GITLAB_API_ENDPOINT: Your gitlab instaqnce's endpoint
62+
* Default https://gitlab.com/api/v4
63+
* GITLAB_PERSONAL_TOKEN: Grant api read/access permission
64+
* GITLAB_PROJECT_ID: Your project id that is located under settings > general
65+
* TARGET_BRANCH: The branch to look for release tags (ie master)
66+
* TARGET_TAG_REGEX: Regular expression of the release tags to search (ie: ^release-.*$)
67+
* TZ: The timezone for your release notes
68+
* Default "Australia/Melbourne"
69+
* ISSUE_CLOSED_SECONDS: The amount of seconds to search after the last commit, useful for Merge Requests that close their tickets a second after the commit.
70+
* Default 0
71+
72+
## Building and Running locally
73+
74+
```bash
75+
export GITLAB_PERSONAL_TOKEN=MYGITLABACCESSTOKEN
76+
export GITLAB_PROJECT_ID=99
77+
export GITLAB_API_ENDPOINT=https://my.gitlab.com/api/v4
78+
79+
// run docker to build my local version
80+
docker build -t local-gitlab-release-note-generator .
81+
82+
// run my local version
83+
docker container run \
84+
-e TZ=America/New_York \
85+
-e GITLAB_API_ENDPOINT=$GITLAB_API_ENDPOINT \
86+
-e GITLAB_PERSONAL_TOKEN=$GITLAB_PERSONAL_TOKEN \
87+
-e GITLAB_PROJECT_ID=$GITLAB_PROJECT_ID \
88+
-e TARGET_BRANCH=master \
89+
-e TARGET_TAG_REGEX=^release-.*$ \
90+
local-gitlab-release-note-generator
91+
92+
```
93+
5794
## TODO:
5895
### Feature
5996
- Release notes generation on selected tag

app/env.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,8 @@ exports.GITLAB_PROJECT_ID = process.env.GITLAB_PROJECT_ID || "12345678"; // Your
44
exports.TARGET_BRANCH = process.env.TARGET_BRANCH;
55
exports.TARGET_TAG_REGEX = process.env.TARGET_TAG_REGEX ? new RegExp(process.env.TARGET_TAG_REGEX): undefined;
66
exports.TZ = process.env.TZ || "Australia/Melbourne"; // TZ variable is for better logging
7-
exports.NODE_ENV = process.env.NODE_ENV;
7+
exports.NODE_ENV = process.env.NODE_ENV;
8+
9+
// will looks for issues closed this many seconds after the tag, this may happen if the issue is merged via a MR and automatially closed
10+
// example -e GITLAB_ISSUE_SECOND_DELAY=60 will catch issues closed up to 60 seconds after the tag is created.
11+
exports.ISSUE_CLOSED_SECONDS = process.env.ISSUE_CLOSED_SECONDS || "0"

app/lib/generator.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,19 @@ exports.generate = async () => {
1414

1515
if (!_.get(latestTag, "commit.committed_date") || !_.get(secondLatestTag, "commit.committed_date")) throw new Error(`Cannot find latest and second latest tag. Abort the program!`);
1616
const startDate = _.get(secondLatestTag, "commit.committed_date");
17-
const endDate = _.get(latestTag, "commit.committed_date");
17+
let endDate = _.get(latestTag, "commit.committed_date");
18+
19+
// allow the end date to be adjusted by a few seconds to catch issues that are automatially closed by
20+
// a MR and are time stamped a few seconds later.
21+
if (Env.ISSUE_CLOSED_SECONDS > 0) {
22+
Logger.debug(`EndDate: ${endDate}`);
23+
Logger.debug(`Adding Seconds: ${Env.ISSUE_CLOSED_SECONDS}`);
24+
endDate = Moment.tz(endDate, Env.TZ).add(Env.ISSUE_CLOSED_SECONDS, "seconds").utc().format();
25+
Logger.debug(`New End Date: ${endDate}`);
26+
}
27+
1828
const changeLog = await ChangelogLib.getChangelogByStartAndEndDate(startDate, endDate);
1929
const changeLogContent = await ChangelogLib.generateChangeLogContent(changeLog, {useSlack: false});
2030
Logger.debug(`Changelog: ${changeLogContent}`);
2131
return await TagLib.upsertTagDescriptionByProjectIdAndTag(Env.GITLAB_PROJECT_ID, latestTag, changeLogContent);
22-
};
32+
};

0 commit comments

Comments
 (0)