Skip to content

Commit

Permalink
Introduce create ticket script
Browse files Browse the repository at this point in the history
The script automates github issue to Jita ticket mirroring.

Signed-off-by: Or Shoval <[email protected]>
  • Loading branch information
oshoval committed Nov 25, 2021
1 parent bc5d4c4 commit b2c7df2
Show file tree
Hide file tree
Showing 19 changed files with 784 additions and 146 deletions.
19 changes: 3 additions & 16 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,42 +1,29 @@
# This is a basic workflow to help you get started with Actions

name: CI

# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches: [ main ]
pull_request:
branches: [ main ]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

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

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

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

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest tox pylint
pip install -r requirements.txt
pip install tox
- name: Test with tox
run: |
tox
tox
130 changes: 2 additions & 128 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,129 +1,3 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
__pycache__
secret*.txt
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM fedora:32

RUN dnf install -y python3 git pip \
&& dnf clean all \
&& rm -rf /var/cache/yum

RUN pip install requests jira
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright [yyyy] [name of copyright owner]
Copyright 2021 Red Hat, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
61 changes: 60 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,61 @@
# github2jira
Scrap github issues and create Jira tickets
github2jira automates mirroring of github issues to Jira tickets.

The tool scans github for issues that match the desired criteria,
and for each one of them creates a Jira ticket (unless it already exists).

## One time configuration
1. Create github token https://github.com/settings/tokens, refer it as `GITHUB_TOKEN`
2. Make sure you have a Jira bot access (either a user:pass or user:token), refer as `JIRA_USERNAME`,`JIRA_TOKEN`
3. Get your Jira project id, refer as `JIRA_PROJECT_ID`
`curl -s -u JIRA_USERNAME:JIRA_TOKEN -X GET -H "Content-Type: application/json" <JIRA_SERVER>/rest/api/latest/project/<JIRA_PROJECT> | jq .id`

## Running manually

1. export the following envvars:
```
export JIRA_SERVER=<..> # for example https://nmstate.atlassian.net
export JIRA_PROJECT=<..> # name of the Jira project (ticket names are JIRA_PROJECT-#)
export JIRA_PROJECT_ID=<..> # see "One time configuration" section
export JIRA_COMPONENT=<..> # which component to set in the created tickets
export GITHUB_OWNER=<..> # the x of https://github.com/x/y
export GITHUB_REPO=<..> # the y of https://github.com/x/y
export GITHUB_LABEL=<..> # which label to filter
export JIRA_USERNAME=<..> # see "One time configuration" section
export JIRA_TOKEN=<..> # see "One time configuration" section
export GITHUB_TOKEN=<..> # see "One time configuration" section
```

2. Run `./main.py` in order to fetch github issues and create a ticket for them

### Additional settings

`dryrun`: Use `./main.py --dryrun` in order to run the tool in dryrun mode.
dryrun mode will fetch github issues, and report what Jira tickets it would create,
but without creating them.

`--issue`: Use `./main.py --issue=<issue_id>` in order to create an issue for
a specified issue id.
No additional checks are performed in this case.

## Running as k8s payload

In order to have a fully automated mirroring process,
it is suggested to run the tool as a cron jon.

One of the methods to achieve it, is to run it as k8s CronJob payload.

### One time configuration: Build docker image for the script

1. From the project folder, run `docker build -f Dockerfile -t <image> .`
once its done, push it to your image repository, or rename and push to a local registry.

### Deploy as k8s payload

1. Create secret.txt with the exports from the section above (include the export command).

2. Create a configmap for the txt file
`kubectl create configmap git-token --from-file=secret.txt`

3. Deploy either a pod or a CronJob (see manifests folder).
Empty file added github2jira/__init__.py
Empty file.
34 changes: 34 additions & 0 deletions github2jira/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# This file is part of the github2jira project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Copyright 2021 Red Hat, Inc.
#

import os


class Config:
def __init__(self, var_names):
self._vars = {name: None for name in var_names}

@property
def vars(self):
return self._vars

def Load(self):
for var_name in self._vars.keys():
value = os.getenv(var_name)
if value is None:
raise NameError(f"can't find {var_name}")
self._vars[var_name] = value
Loading

0 comments on commit b2c7df2

Please sign in to comment.