diff --git a/README.md b/README.md index deda460..fbfb8ba 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/action.yml b/action.yml index 24945d8..5eb64fb 100644 --- a/action.yml +++ b/action.yml @@ -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' diff --git a/connectors/jira.js b/connectors/jira.js new file mode 100644 index 0000000..a08c6f8 --- /dev/null +++ b/connectors/jira.js @@ -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 +} + diff --git a/index.js b/index.js index 893969d..22caa9c 100644 --- a/index.js +++ b/index.js @@ -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 }); @@ -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); @@ -38,6 +50,7 @@ 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, }) @@ -45,8 +58,16 @@ const run = async () => { 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); } @@ -54,7 +75,6 @@ const run = async () => { const date = new Date(); const month = date.toLocaleString('default', { month: 'long' }); - const url = `/repos/${params.owner}/${params.repo}/pulls/${pullNumber}`; params.body = descriptionTemplate diff --git a/package.json b/package.json index c762d37..7752cbc 100644 --- a/package.json +++ b/package.json @@ -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": {