Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
Added README file
Added prettier and ran code through it
Converted code from using axios to using got
Introduced jira-client to reuse between functions
Instead of 'require' use 'import' statements
  • Loading branch information
rodush committed Aug 2, 2022
0 parents commit 433c709
Show file tree
Hide file tree
Showing 15 changed files with 1,974 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dist
coverage
node_modules
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Ignore artifacts:
coverage
dist
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"trailingComma": "es5",
"tabWidth": 2,
"semi": false,
"singleQuote": true
}
76 changes: 76 additions & 0 deletions REAMDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Jira Release github action

The purpose of this github action is to synchronize Releases in Github with the Releases in Jira (Cloud).

## How it works

When a new Pre-Release is published in Github (essentially, when a new tag is created), the event is emitted to which Github Actions enabled for the repository can react.
The action will fetch details about the Release - the name and the tag. Then, it will grab the last 2 tags and, will get the change log between those, loop through each commit, and from the commit summary will try to extract the JIRA issue number.

**WARNING**: The action is built with the assumption that commit messages are written in a certain format: `JIRA-123: Commit summary message` (actually, it's a format supported by the commitizen project, see <https://www.npmjs.com/package/commitlint-config-jira>).

Next, the Action will go to Jira and create a new Release named after the repository name concatenated via '-' with the tag name (if tag starts with the `v` prefix, then this prefix will be dropped). The title of the Github Release will be used as a description of the Release in Jira.

**Example:**

![](./docs/jira-releases-page.png)

Eventually, the Action will update all the relevant Jira tickets with the "Fix versions" set to the current Jira Release name.\
Keep in mind that the version will be appended to already existing versions on the ticket with the `update` operation:

![](docs/jira-fix-versions.png)

## How to use

In the `.github/` directory within the repository create a new workflow file with the contents like this:

```yaml
name: Sync Github and Jira release

on:
release:
types: [published]

jobs:
jira_release:
timeout-minutes: 5
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Create Jira Release
id: jira-release
uses: rodush/github-actions-jira-release@v1
with:
project_id: 13327
project_key: "TRS"
env:
JIRA_API_USER: ${{ secrets.ATLASSIAN_CLOUD_USER }}
JIRA_API_TOKEN: ${{ secrets.ATLASSIAN_CLOUD_APIKEY }}
ATLASSIAN_CLOUD_DOMAIN: ${{ secrets.ATLASSIAN_CLOUD_DOMAIN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```
The example above expects a list of certain secrets available in the repository:
- `ATLASSIAN_CLOUD_USER`
- `ATLASSIAN_CLOUD_APIKEY`
- `ATLASSIAN_CLOUD_DOMAIN`

### Action inputs

The action requires 2 input parameters provided:

- `project_id` , used in the API calls
- `project_key`, used in the regular expression to extract Jira ticket number from the commit summary message

It also requires 4 environment variables:

- `JIRA_API_USER`
- `JIRA_API_TOKEN`
- `ATLASSIAN_CLOUD_DOMAIN`
- `GITHUB_TOKEN`

### Permissions

The API user to communicate with Jira needs to have the "Admin" rights for a project where Releases are to be created.
18 changes: 18 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: 'Create Jira Release'
description: 'Creates new Jira Release (version) when Github release is published'
inputs:
project_id:
description: 'Id of the Jira project (int64)'
required: true
project_key:
description: 'Project key. Used to pick ticket ids from the commit messages'
required: true
default: "SLI"
outputs:
jira_release_id:
description: 'Jira Release ID'
jira_release_name:
description: 'Jira Release Name'
runs:
using: 'node12'
main: 'dist/index.js'
Binary file added docs/jira-fix-versions.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/jira-releases-page.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 433c709

Please sign in to comment.