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
7 changes: 7 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
GITHUB_USER=<user>
GITHUB_TOKEN=***********
JIRA_USER=<user>
JIRA_PASSWORD=*********
JIRA_URI=http://localhost:8080
JIRA_PROJECT=SET1
JIRA_ALIVE_URI=http://localhost:8080/rest/api/2/status
108 changes: 101 additions & 7 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,110 @@
{
"env": {
"browser": false,
"es2021": true
},
"extends": [
"standard"
"eslint:recommended"
],
"parserOptions": {
"ecmaVersion": 12,
"ecmaVersion": 2018,
"sourceType": "module"
},
"env": {
"es6": true,
"node": true,
"browser": true
},
"rules": {
"semi": [2, "always"]
"strict": [
2,
"global"
],
"semi": [
2,
"always"
],
"quotes": [
2,
"single",
{
"allowTemplateLiterals": true
}
],
"curly": 2,
"brace-style": [
2,
"stroustrup",
{
"allowSingleLine": true
}
],
"indent": [
2,
4,
{
"SwitchCase": 1,
"VariableDeclarator": 2
}
],
"key-spacing": [
2,
{
"beforeColon": false,
"afterColon": true
}
],
"space-before-blocks": [
2,
"always"
],
"space-before-function-paren": [
2,
"never"
],
"keyword-spacing": [
2,
{
"overrides": {
"if": {
"after": false
},
"for": {
"after": false
},
"while": {
"after": false
}
}
}
],
"space-in-parens": [
2,
"never"
],
"comma-spacing": [
2,
{
"before": false,
"after": true
}
],
"eqeqeq": 2,
"no-multi-spaces": 2,
"space-infix-ops": 2,
"no-debugger": 2,
"no-console": 0,
"no-var": 2,
"no-trailing-spaces": 2,
"eol-last": 0,
"no-unused-vars": 2,
"no-underscore-dangle": 0,
"no-alert": 2,
"no-lone-blocks": 1,
"no-warning-comments": 1,
"no-empty-function": 2,
"default-case": 2,
"handle-callback-err": 2,
"no-lonely-if": 2,
"no-self-compare": 2,
"no-throw-literal": 2,
"implicit-arrow-linebreak": 2,
"arrow-spacing": 2
}
}
18 changes: 0 additions & 18 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on:
push:
branches: [ main, rel* ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ main ]
schedule:
- cron: '44 12 * * 0'
Expand All @@ -22,28 +21,11 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v2

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: ${{ matrix.language }}

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl

# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language

#- run: |
# make bootstrap
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
38 changes: 38 additions & 0 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: 'Integration Tests'

on:
pull_request:

jobs:
build:
runs-on: ubuntu-latest
name: 'Run Integration Tests'
env:
USERNAME: ${{ github.actor }}
PASSWORD: ${{ github.token }}

steps:
- uses: actions/checkout@v2
- name: 'Use Node.js 12.x'
uses: actions/setup-node@v1
with:
node-version: 12.x
- name: 'Install Dependencies'
run: npm install
- name: 'Login to GitHub registry'
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ env.USERNAME }}
password: ${{ env.PASSWORD }}
- name: 'Execute Integration Tests'
run: npm run test:integration
env:
GITHUB_USER: ${{ env.USERNAME }}
GITHUB_TOKEN: ${{ env.PASSWORD }}
GITHUB_RUN: true
JIRA_USER: admin
JIRA_PASSWORD_INTEGRATION: ${{ secrets.JIRA_PASSWORD_INTEGRATION}}
JIRA_PROJECT: SET1
JIRA_URI: 'http://localhost:8080'
JIRA_ALIVE_URI: 'http://localhost:8080/rest/api/2/status'
2 changes: 1 addition & 1 deletion .github/workflows/linter.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Linter

on:
on:
pull_request:

jobs:
Expand Down
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,31 @@ The Unit Tests have been implemented using `Mocha` and `Chai`. For the test cove

To run them locally, simply run `npm run test`.

## Run the Integration Tests
The integration tests built for that project are based on a public Docker image offering a vanilla Jira instance on top
of which a dev license and a basic setup have been added as a layer. The tests run for every attempt to merge to master
in order to ensure that the action does what it's supposed to do: raise Jira issues!

In order to make sure that your PR does not break the tests, you can run them locally by executing:

```
npm run test:integration
```

Since the tests use the `dotenv` module, you need to have locally a `.env` file with the key value pairs described in the
`.env.example` file.


The tests then will:

1. search for any running containers serving Jira to http://localhost:8080
2. if any, attempt to stop them
3. pull the relevant image down, if it cannot be found locally
4. spin off a container based on that image
5. validate that the action can create an issue on the Jira instance created
6. validate that teh aforementioned issue has been created

Note that the steps 1 and 2 are applicable only when you execute the tests locally.

## Run the GitHub Action locally
To run this action locally, you can simply build a Docker image and then run it to see that you get the desired result. To do so, follow the instructions below:
Expand Down Expand Up @@ -186,3 +211,6 @@ docker run -e JIRA_USER=$JIRA_USER \
-e RUNS_ON_GITHUB=$RUNS_ON_GITHUB \
<image_name>:<image_version>
```

Alternatively, you can spin off a container via the [integration tests](#run-the-integration-tests) and use the Jira
instance server in http://localhost:8080 as your main target.
66 changes: 35 additions & 31 deletions config/config.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,48 @@
const core = require('@actions/core');

const JIRA_CONFIG = {
JIRA_USER: process.env.JIRA_USER || core.getInput('JIRA_USER'),
JIRA_PASSWORD: process.env.JIRA_PASSWORD || core.getInput('JIRA_PASSWORD'),
JIRA_PROJECT: process.env.JIRA_PROJECT || core.getInput('JIRA_PROJECT'),
JIRA_URI: process.env.JIRA_URI || core.getInput('JIRA_URI'),
ISSUE_TYPE: process.env.ISSUE_TYPE || core.getInput('ISSUE_TYPE'),
JIRA_ISSUE_CREATION_ENDPOINT: '/rest/api/2/issue',
JIRA_ISSUE_AUTH_SESSION_ENDPOINT: '/rest/auth/1/session',
JIRA_ISSUE_SEARCH_ENDPOINT: '/rest/api/2/search',
JIRA_ISSUE_SEARCH_PAYLOAD_RESOLVED_ISSUES: {
jql: process.env.JQL_SEARCH_PAYLOAD_RESOLVED_ISSUES || core.getInput('JQL_SEARCH_PAYLOAD_RESOLVED_ISSUES'),
startAt: 0,
maxResults: 1000,
fields: [
'summary'
]
},
JIRA_ISSUE_SEARCH_PAYLOAD_OPEN_ISSUES: {
jql: process.env.JQL_SEARCH_PAYLOAD_OPEN_ISSUES || core.getInput('JQL_SEARCH_PAYLOAD_OPEN_ISSUES'),
startAt: 0,
maxResults: 1000,
fields: [
'summary'
]
}
get: () => {
return {
JIRA_USER: process.env.JIRA_USER || core.getInput('JIRA_USER'),
JIRA_PASSWORD: process.env.JIRA_PASSWORD || core.getInput('JIRA_PASSWORD'),
JIRA_PROJECT: process.env.JIRA_PROJECT || core.getInput('JIRA_PROJECT'),
JIRA_URI: process.env.JIRA_URI || core.getInput('JIRA_URI'),
ISSUE_TYPE: process.env.ISSUE_TYPE || core.getInput('ISSUE_TYPE'),
JIRA_ISSUE_CREATION_ENDPOINT: '/rest/api/2/issue',
JIRA_ISSUE_AUTH_SESSION_ENDPOINT: '/rest/auth/1/session',
JIRA_ISSUE_SEARCH_ENDPOINT: '/rest/api/2/search',
JIRA_ISSUE_SEARCH_PAYLOAD_RESOLVED_ISSUES: {
jql: process.env.JQL_SEARCH_PAYLOAD_RESOLVED_ISSUES || core.getInput('JQL_SEARCH_PAYLOAD_RESOLVED_ISSUES'),
startAt: 0,
maxResults: 1000,
fields: [
'summary'
]
},
JIRA_ISSUE_SEARCH_PAYLOAD_OPEN_ISSUES: {
jql: process.env.JQL_SEARCH_PAYLOAD_OPEN_ISSUES || core.getInput('JQL_SEARCH_PAYLOAD_OPEN_ISSUES'),
startAt: 0,
maxResults: 1000,
fields: [
'summary'
]
}
};
}
};

const REST_CONFIG = {
HEADER_ACCEPT_APPLICATION_JSON: 'application/json'
HEADER_ACCEPT_APPLICATION_JSON: 'application/json'
};

const UTILS = {
TEMPLATES_DIR: (core.getInput('RUNS_ON_GITHUB') || process.env.RUNS_ON_GITHUB) === 'true' ? './actions-jira-integration/templates' : './templates',
PAYLOADS_DIR: (core.getInput('RUNS_ON_GITHUB') || process.env.RUNS_ON_GITHUB) === 'true' ? './actions-jira-integration/payloads' : './payloads',
CREATE_JIRA_ISSUE_PAYLOAD_TEMPLATE: 'issueCreation.template'
TEMPLATES_DIR: (core.getInput('RUNS_ON_GITHUB') || process.env.RUNS_ON_GITHUB) === 'true' ? './actions-jira-integration/templates' : './templates',
PAYLOADS_DIR: (core.getInput('RUNS_ON_GITHUB') || process.env.RUNS_ON_GITHUB) === 'true' ? './actions-jira-integration/payloads' : './payloads',
CREATE_JIRA_ISSUE_PAYLOAD_TEMPLATE: 'issueCreation.template'
};

module.exports = {
JIRA_CONFIG: JIRA_CONFIG,
REST_CONFIG: REST_CONFIG,
UTILS: UTILS
JIRA_CONFIG: JIRA_CONFIG,
REST_CONFIG: REST_CONFIG,
UTILS: UTILS
};
Loading