Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ This workflow will be running only if it's run for pull request. Otherwise it wi
```
- `description_template_filepath`: If you need to use more complex template you can use MD file. Use {{feature_commits}} in the template to replace it with list of commits matched using feature_commit_pattern and {{chores_commits}} will be replace by commit description list not matched feature_commit_pattern. This will overwrite description_template. If file not exist will fallback to description_template. Sample template file can be found [here](https://github.com/szymansd/auto-release-notes/blob/main/.github/templates/deployment.md).
- `title_template`: This is a pattern for PR name. {{date}} will be replace by D MM. Default value: `Deployment {{date}}`

- `ticket_management`: If you use ticket management you can pass it here and job will replace feature commits with JIRA issue titles. Possible values: jira
- `jira_username`: If you are using JIRA as your ticket management system you can have add username and password so instead of commits release notes will have issue titles
- `jira_password`: If you are using JIRA as your ticket management system you can have add username and password so instead of commits release notes will have issue titles
- `jira_url`: If you are using JIRA as your ticket management system you can add JIRA url so job will connect and try to check all linked comits. Instead of commits messages it will display JIRA titles

### Example workflow

```yaml
Expand Down
12 changes: 12 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ inputs:
title_template:
description: 'This is a pattern for PR name. {{date}} will be replace by D MM'
required: false
ticket_management:
description: 'IF you use ticket management you can pass it here and job will replace feature commits with JIRA issue titles. Possible options: jira'
required: false
jira_username:
description: 'If you are using JIRA as your ticket management system you can have add username and password so instead of commits release notes will have issue titles'
required: false
jira_password:
description: 'If you are using JIRA as your ticket management system you can have add username and password so instead of commits release notes will have issue titles'
required: false
jira_url:
description: 'If you are using JIRA as your ticket management system you can add JIRA url so job will connect and try to check all linked comits. Instead of commits messages it will display JIRA titles'
required: false
runs:
using: 'node16'
main: 'dist/index.js'
31 changes: 31 additions & 0 deletions connectors/jira.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import JiraApi from 'jira-client';

let jira = null;

function connect(core) {
jira = new JiraApi({
protocol: 'https',
host: core.getInput('jira_url'),
username: core.getInput('jira_username'),
password: core.getInput('jira_password'),
apiVersion: '2',
strictSSL: true
});
}

function find(issueNumber) {
jira.findIssue(issueNumber)
.then(issue => {
return issue.fields.summary;
})
.catch(err => {
console.error(err);
return issueNumber;
});
}

module.exports = {
connect: connect,
find: find
}

26 changes: 23 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
const core = require('@actions/core');
const github = require('@actions/github');
const fs = require('fs').promises;
const jira_connector = require('connectors/jira');

const issuesMappers = {
jira: jira_connector
}

const run = async () => {
const githubToken = core.getInput('github_token', { required: true });
Expand All @@ -12,6 +17,13 @@ const run = async () => {
`;
const titleTemplate = core.getInput('title_template') || `Deployment {{date}}`;
const descriptionTemplateFilepath = core.getInput('description_template_filepath');

// Issues management systems
const issuesManagementSystem = core.getInput('ticket_management');
let issueFinder = null;
if (issuesManagementSystem && issuesMappers[issuesManagementSystem]) {
issueFinder = issuesMappers[issuesManagementSystem].connect(core);
}

try {
const templateFileBuffer = await fs.readFile(descriptionTemplateFilepath);
Expand All @@ -38,23 +50,31 @@ const run = async () => {

const featurePattern = core.getInput("feature_commit_pattern");

const regex = new RegExp(featurePattern+'\d*', 'gmi');
const { data } = await octokit.request(`GET /repos/${params.owner}/${params.repo}/pulls/${params.pull_number}/commits`, {
...params,
})
const features = [];
const chores = [];

data.forEach(({ commit }) => {
if(commit.message.match(featurePattern)) {
features.push(commit.message);
const commitId = commit.message.match(regex);
if (commitId) {
if (!features.find((featureMessage) => featureMessage.includes(commitId))) {
if (issueFinder) {
let issueTitle = issueFinder.find(commitId);
features.push(`${commitId}-${issueTitle}`);
} else {
features.push(commit.message);
}
}
} else {
chores.push(commit.message);
}
});

const date = new Date();
const month = date.toLocaleString('default', { month: 'long' });

const url = `/repos/${params.owner}/${params.repo}/pulls/${pullNumber}`;

params.body = descriptionTemplate
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "auto-release-notes",
"version": "0.0.1",
"version": "0.0.2",
"description": "A GitHub action to create release notes.",
"main": "dist/index.js",
"scripts": {
Expand Down