Skip to content

Commit 676bd33

Browse files
authored
Merge pull request #1 from oshoval/pr
Introduce create ticket script
2 parents bc5d4c4 + b62d75b commit 676bd33

21 files changed

+906
-146
lines changed

.github/workflows/main.yml

+3-16
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,29 @@
1-
# This is a basic workflow to help you get started with Actions
2-
31
name: CI
42

5-
# Controls when the workflow will run
63
on:
7-
# Triggers the workflow on push or pull request events but only for the main branch
84
push:
95
branches: [ main ]
106
pull_request:
117
branches: [ main ]
128

13-
# Allows you to run this workflow manually from the Actions tab
149
workflow_dispatch:
1510

16-
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
1711
jobs:
18-
# This workflow contains a single job called "build"
1912
build:
20-
# The type of runner that the job will run on
2113
runs-on: ubuntu-latest
2214

23-
# Steps represent a sequence of tasks that will be executed as part of the job
2415
steps:
25-
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
2616
- uses: actions/checkout@v2
2717

2818
- name: Setup Python
2919
uses: actions/[email protected]
3020
with:
31-
# Version range or exact version of a Python version to use, using SemVer's version range syntax.
3221
python-version: "3.6"
3322

3423
- name: Install dependencies
3524
run: |
36-
python -m pip install --upgrade pip
37-
pip install flake8 pytest tox pylint
38-
pip install -r requirements.txt
39-
25+
pip install tox
26+
4027
- name: Test with tox
4128
run: |
42-
tox
29+
tox

.gitignore

+2-128
Original file line numberDiff line numberDiff line change
@@ -1,129 +1,3 @@
1-
# Byte-compiled / optimized / DLL files
2-
__pycache__/
3-
*.py[cod]
4-
*$py.class
5-
6-
# C extensions
7-
*.so
8-
9-
# Distribution / packaging
10-
.Python
11-
build/
12-
develop-eggs/
13-
dist/
14-
downloads/
15-
eggs/
16-
.eggs/
17-
lib/
18-
lib64/
19-
parts/
20-
sdist/
21-
var/
22-
wheels/
23-
pip-wheel-metadata/
24-
share/python-wheels/
25-
*.egg-info/
26-
.installed.cfg
27-
*.egg
28-
MANIFEST
29-
30-
# PyInstaller
31-
# Usually these files are written by a python script from a template
32-
# before PyInstaller builds the exe, so as to inject date/other infos into it.
33-
*.manifest
34-
*.spec
35-
36-
# Installer logs
37-
pip-log.txt
38-
pip-delete-this-directory.txt
39-
40-
# Unit test / coverage reports
41-
htmlcov/
1+
__pycache__
2+
secret*.txt
423
.tox/
43-
.nox/
44-
.coverage
45-
.coverage.*
46-
.cache
47-
nosetests.xml
48-
coverage.xml
49-
*.cover
50-
*.py,cover
51-
.hypothesis/
52-
.pytest_cache/
53-
54-
# Translations
55-
*.mo
56-
*.pot
57-
58-
# Django stuff:
59-
*.log
60-
local_settings.py
61-
db.sqlite3
62-
db.sqlite3-journal
63-
64-
# Flask stuff:
65-
instance/
66-
.webassets-cache
67-
68-
# Scrapy stuff:
69-
.scrapy
70-
71-
# Sphinx documentation
72-
docs/_build/
73-
74-
# PyBuilder
75-
target/
76-
77-
# Jupyter Notebook
78-
.ipynb_checkpoints
79-
80-
# IPython
81-
profile_default/
82-
ipython_config.py
83-
84-
# pyenv
85-
.python-version
86-
87-
# pipenv
88-
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
89-
# However, in case of collaboration, if having platform-specific dependencies or dependencies
90-
# having no cross-platform support, pipenv may install dependencies that don't work, or not
91-
# install all needed dependencies.
92-
#Pipfile.lock
93-
94-
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
95-
__pypackages__/
96-
97-
# Celery stuff
98-
celerybeat-schedule
99-
celerybeat.pid
100-
101-
# SageMath parsed files
102-
*.sage.py
103-
104-
# Environments
105-
.env
106-
.venv
107-
env/
108-
venv/
109-
ENV/
110-
env.bak/
111-
venv.bak/
112-
113-
# Spyder project settings
114-
.spyderproject
115-
.spyproject
116-
117-
# Rope project settings
118-
.ropeproject
119-
120-
# mkdocs documentation
121-
/site
122-
123-
# mypy
124-
.mypy_cache/
125-
.dmypy.json
126-
dmypy.json
127-
128-
# Pyre type checker
129-
.pyre/

Dockerfile

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM fedora:32
2+
3+
RUN dnf install -y python3 git pip \
4+
&& dnf clean all \
5+
&& rm -rf /var/cache/yum
6+
7+
RUN pip install requests jira

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright [yyyy] [name of copyright owner]
189+
Copyright 2021 Red Hat, Inc.
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.

README.md

+63-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,64 @@
11
# github2jira
2-
Scrap github issues and create Jira tickets
2+
github2jira automates mirroring of github issues to Jira tickets.
3+
4+
The tool scans github for issues that match the desired criteria,
5+
and for each one of them creates a Jira ticket (unless it already exists).
6+
7+
## One time configuration
8+
1. Create github token https://github.com/settings/tokens, refer it as `GITHUB_TOKEN`
9+
2. Make sure you have a Jira bot access (either a user:pass or user:token), refer as `JIRA_USERNAME`,`JIRA_TOKEN`
10+
3. Get your Jira project id, refer as `JIRA_PROJECT_ID`
11+
`curl -s -u JIRA_USERNAME:JIRA_TOKEN -X GET -H "Content-Type: application/json" <JIRA_SERVER>/rest/api/latest/project/<JIRA_PROJECT> | jq .id`
12+
13+
## Running manually
14+
15+
1. export the following envvars:
16+
```
17+
export JIRA_SERVER=<..> # for example https://nmstate.atlassian.net
18+
export JIRA_PROJECT=<..> # name of the Jira project (ticket names are JIRA_PROJECT-#)
19+
export JIRA_PROJECT_ID=<..> # see "One time configuration" section
20+
export JIRA_COMPONENT=<..> # which component to set in the created tickets
21+
export GITHUB_OWNER=<..> # the x of https://github.com/x/y
22+
export GITHUB_REPO=<..> # the y of https://github.com/x/y
23+
export GITHUB_LABEL=<..> # which label to filter
24+
25+
export JIRA_USERNAME=<..> # see "One time configuration" section
26+
export JIRA_TOKEN=<..> # see "One time configuration" section
27+
export GITHUB_TOKEN=<..> # see "One time configuration" section
28+
```
29+
30+
For Jira basic auth set JIRA_USERNAME=<USER>, JIRA_TOKEN<PASSWORD/TOKEN>
31+
For Jira Personal Access Token set JIRA_USERNAME="", JIRA_TOKEN=<PAT>
32+
33+
2. Run `./main.py` in order to fetch github issues and create a ticket for them
34+
35+
### Additional settings
36+
37+
`dryrun`: Use `./main.py --dryrun` in order to run the tool in dryrun mode.
38+
dryrun mode will fetch github issues, and report what Jira tickets it would create,
39+
but without creating them.
40+
41+
`--issue`: Use `./main.py --issue=<issue_id>` in order to create an issue for
42+
a specified issue id.
43+
No additional checks are performed in this case.
44+
45+
## Running as k8s payload
46+
47+
In order to have a fully automated mirroring process,
48+
it is suggested to run the tool as a cron jon.
49+
50+
One of the methods to achieve it, is to run it as k8s CronJob payload.
51+
52+
### One time configuration: Build docker image for the script
53+
54+
1. From the project folder, run `docker build -f Dockerfile -t <image> .`
55+
once its done, push it to your image repository, or rename and push to a local registry.
56+
57+
### Deploy as k8s payload
58+
59+
1. Create secret.txt with the exports from the section above (include the export command).
60+
61+
2. Create a configmap for the txt file
62+
`kubectl create configmap git-token --from-file=secret.txt`
63+
64+
3. Deploy either a pod or a CronJob (see manifests folder).

github2jira/__init__.py

Whitespace-only changes.

github2jira/config.py

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# This file is part of the github2jira project
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
# Copyright 2021 Red Hat, Inc.
16+
#
17+
18+
import os
19+
20+
21+
class Config:
22+
def __init__(self, var_names):
23+
self._vars = {name: None for name in var_names}
24+
25+
@property
26+
def vars(self):
27+
return self._vars
28+
29+
def Load(self):
30+
for var_name in self._vars.keys():
31+
value = os.getenv(var_name)
32+
if value is None:
33+
raise NameError(f"can't find {var_name}")
34+
self._vars[var_name] = value

0 commit comments

Comments
 (0)