Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrades and code cleanup #42

Merged
merged 1 commit into from
Nov 3, 2020
Merged
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
31 changes: 31 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: release

# Allow to trigger this workflow manually and enter a release version to release
# See: https://github.blog/changelog/2020-07-06-github-actions-manual-triggers-with-workflow_dispatch/
on:
workflow_dispatch:
inputs:
releaseVersion:
description: "Release tag version"
required: true

jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout branch
uses: actions/checkout@v2
with:
ref: "master"
fetch-depth: 0
- uses: oleksiyrudenko/gha-git-credentials@v1
with:
token: "${{ secrets.GITHUB_TOKEN }}"
- name: Use Node.js
uses: actions/setup-node@v2-beta
with:
node-version: 15
- name: Release version
run: npx -p @release-it/bumper -p release-it@13.6.2 release-it --verbose --increment ${{ github.event.inputs.releaseVersion }}
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
22 changes: 22 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: run-tests

on: [push, pull_request]

jobs:
tests:
strategy:
fail-fast: true
matrix:
node: [ '10', '12', '14', '15' ] # https://nodejs.org/en/about/releases/
name: NPM test - (Node ${{ matrix.node }})
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- uses: actions/setup-node@v2-beta
with:
node-version: ${{ matrix.node }}
- name: install dependencies
run: npm ci
- name: run tests
run: npm test
22 changes: 22 additions & 0 deletions .release-it.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"hooks": {
"before:release": [
"npx auto-changelog --latest-version ${version} --ignore-commit-pattern \"^🔖 Release\" --commit-limit false --hide-credit --template https://raw.githubusercontent.com/release-it/release-it/master/templates/keepachangelog.hbs",
"git add CHANGELOG.md"
]
},
"git": {
"commitMessage": "🔖 Release ${version}",
"tagName": "${version}"
},
"github": {
"release": true,
"releaseNotes": "npx auto-changelog --latest-version ${version} --stdout --ignore-commit-pattern \"^🔖 Release\" --commit-limit false --hide-credit --template https://raw.githubusercontent.com/release-it/release-it/master/templates/changelog-compact.hbs"
},
"plugins": {
"@release-it/bumper": {
"in": "package.json",
"out": "package.json"
}
}
}
17 changes: 0 additions & 17 deletions .travis.yml

This file was deleted.

34 changes: 17 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# JIRA Smart Commits
[![Stable Version](https://img.shields.io/npm/v/jira-smart-commit.svg)](https://www.npmjs.com/package/jira-smart-commit)
[![Build Status](https://travis-ci.org/jessedobbelaere/jira-smart-commit.svg?branch=master)](https://travis-ci.org/jessedobbelaere/jira-smart-commit)
# JIRA Smart Commit

![tests](https://github.com/jessedobbelaere/jira-smart-commit/workflows/run-tests/badge.svg)
[![GitHub release](https://img.shields.io/github/release/jessedobbelaere/jira-smart-commit.svg)](https://github.com/jessedobbelaere/jira-smart-commit/releases/latest)
[![Dependabot Status](https://api.dependabot.com/badges/status?host=github&repo=jessedobbelaere/fork-cms-webpack-boilerplate)](https://dependabot.com)
[![MIT license](http://img.shields.io/badge/license-MIT-brightgreen.svg)](http://opensource.org/licenses/MIT)
[![Downloads](https://img.shields.io/npm/dt/jira-smart-commit.svg)](https://www.npmjs.com/package/jira-smart-commit)
Expand All @@ -11,7 +12,8 @@ A Node.js git hook script to prefix commits automatically with the JIRA ticket,
## Usage

### Installation
1. Install [Husky](https://www.npmjs.com/package/husky) in your project to configure Git hooks easily

1. Install [Husky](https://www.npmjs.com/package/husky) in your project to configure Git hooks easily.

```bash
npm install --save-dev husky
Expand All @@ -28,29 +30,27 @@ npm install --save-dev jira-smart-commit
```json
"husky": {
"hooks": {
"commit-msg": "jira-smart-commit SPAN",
"commit-msg": "jira-smart-commit YOUR_JIRA_ISSUE_KEY",
"pre-commit": "lint-staged"
}
},
```

or environment variables

- TAG_MATCHER - regular expression
- TAG_MATCH_INDEX - match index
- DEBUG - if true will console log some data about branch, matches array etc
Alternatively: use a regex to detect the Jira `ISSUE_KEY` in your branch.

example: if your branches have feature/SPAN-1234/some-description template
- `TAG_MATCHER` - regular expression
- `TAG_MATCH_INDEX` - match index

Example: if your branch names looke like `feature/JRA-1234/some-description` template

```
"commit-msg": "TAG_MATCHER=\"^[^/]+/(SPAN-[0-9]+)\" TAG_MATCH_INDEX=1 jira-smart-commit"
"commit-msg": "TAG_MATCHER=\"^[^/]+/(JRA-[0-9]+)\" TAG_MATCH_INDEX=1 jira-smart-commit"
```



4. Do your git commits like usual. If the branch was prefixed with a JIRA tag, your commit message will get prefixed with
the same tag.
the same tag.

```
Branch: TAG-411-husky-git-hooks
Commit message: "Add git hooks to project" → "TAG-411 Add git hooks to project"
Branch: JRA-411-husky-git-hooks
Commit message: "Add git hooks to project" → "JRA-411 Add git hooks to project"
```
10 changes: 5 additions & 5 deletions index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ describe('index.js', () => {
expect(executeScriptMock("SPAN", "SPAN-1-proof-of-concept", "Initial commit✨")).to.equal("SPAN-1 Initial commit✨");
expect(executeScriptMock("PROJECT", "PROJECT-3-githook-test", "Add support for githooks")).to.equal("PROJECT-3 Add support for githooks");
expect(executeScriptMock("TAG", "TAG-5032-add-readme", "Add readme to project")).to.equal("TAG-5032 Add readme to project");
});

process.env.TAG_MATCHER = "^[^/]+/(SPAN-[0-9]+)";
it('should add a prefix to my unprefixed commit message by detecting the tag using regex', () => {
process.env.TAG_MATCHER = "^[^/]+\/(SPAN-[0-9]+)";
process.env.TAG_MATCH_INDEX = "1";
process.env.DEBUG = "true";
expect(executeScriptMock(undefined, "feature/SPAN-1234/init", "Initial commit")).to.equal('SPAN-1234 Initial commit');
expect(executeScriptMock(undefined, "FEAT/SPAN-1234/init", "Initial commit")).to.equal('SPAN-1234 Initial commit');
delete process.env.TAG_MATCHER;
delete process.env.TAG_MATCH_INDEX;
delete process.env.DEBUG;
});

it('should not add a prefix again to my already prefixed commit message', () => {
Expand All @@ -29,7 +29,7 @@ describe('index.js', () => {
expect(executeScriptMock("SPAN", "SPAN-1-proof-of-concept", commitMergeMessage)).to.equal(commitMergeMessage);
});

it('should not add a prefix if branch was not prefixed', () => {
it('should not add a prefix if a branch was not prefixed', () => {
expect(executeScriptMock("TAG", "conquer-the-world-PoC", "Initial commit")).to.equal("Initial commit");
});

Expand Down
Loading