Skip to content

Commit 1b2802c

Browse files
committed
Adding files
Update README.md Create ci.yml
1 parent 6cc8cee commit 1b2802c

File tree

14 files changed

+366
-1
lines changed

14 files changed

+366
-1
lines changed

.github/workflows/ci.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: CI
2+
on:
3+
push:
4+
branches:
5+
- main
6+
7+
jobs:
8+
ci:
9+
strategy:
10+
fail-fast: false
11+
matrix:
12+
python-version: ["3.11"]
13+
poetry-version: ["1.6.1"]
14+
os: [ubuntu-22.04]
15+
runs-on: ${{ matrix.os }}
16+
steps:
17+
- uses: actions/checkout@v4
18+
- uses: actions/setup-python@v4
19+
with:
20+
python-version: ${{ matrix.python-version }}
21+
- name: Run image
22+
uses: abatilo/actions-poetry@v2
23+
with:
24+
poetry-version: ${{ matrix.poetry-version }}
25+
- name: Install the project dependencies
26+
run: poetry install
27+
- name: Build project
28+
run: poetry build
29+
- name: Tests
30+
run: poetry run pytest

.github/workflows/release.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Release
2+
on:
3+
push:
4+
tags:
5+
- '*'
6+
7+
jobs:
8+
release:
9+
strategy:
10+
fail-fast: false
11+
matrix:
12+
python-version: ["3.11"]
13+
poetry-version: ["1.6.1"]
14+
os: [ubuntu-22.04]
15+
runs-on: ${{ matrix.os }}
16+
steps:
17+
- uses: actions/checkout@v4
18+
- uses: actions/setup-python@v4
19+
with:
20+
python-version: ${{ matrix.python-version }}
21+
- name: Run image
22+
uses: abatilo/actions-poetry@v2
23+
with:
24+
poetry-version: ${{ matrix.poetry-version }}
25+
- name: Install the plugin for dynamic versioning
26+
run: poetry self add "poetry-dynamic-versioning[plugin]"
27+
- name: Build project
28+
run: poetry build
29+
- name: Tests
30+
run: poetry run pytest

CONTRIBUTING

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Contributing Guides
2+
Thank you for investing your time in contributing to **git-jira**!
3+
4+
In this guide, you will get an overview of the contribution workflow from opening an issue, creating a PR, reviewing, and
5+
merging the PR.
6+
7+
## How to Get Started
8+
To get an overview of the project, read the [README](README.md).
9+
10+
If you spot a problem with **git-jira**, search if an issue already exists. If not, create an issue, so it can
11+
serve as a centralized thread of communication with you, maintainers and the community.
12+
13+
#### Did you find a bug or have a feature proposal?
14+
- Search if an issue is already registered. If not, create one.
15+
- Fork the repository to your own GitHub account and work from your fork's `main` branch
16+
- Make sure to have a working build and make sure to be covering the changes with tests.
17+
- In case of changes to the usability of the library, please also provide changes on the documentation and examples.
18+
- When finished, create a PR to the original `main` branch. If it's a change that should be limited to a specific
19+
release, create the PR to the specific release instead (e.g. `release/2.5`)
20+
- Be patience, so maintainers can review and merge your code
21+
22+
## Release Flow
23+
- The `main` branch has the latest updates and compatibility of the library.
24+
- Every PR is merged against the `main` branch, except the changes valid only for specific releases.
25+
- Once a PR is merged to the `main` branch, the commits are cherry-picked to the active releases, so they also include
26+
the latest updates of the library. Note that this might be affected by some further changes so the code is compatible
27+
with previous releases.

LICENSE

Lines changed: 1 addition & 1 deletion
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 2024 Intelligent Apps GmbH
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.

MAINTAINERS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fabian Neugart <[email protected]>
2+
Nikolai Lopin <[email protected]>

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
![](out.gif)
3+
4+
## Installation
5+
6+
```bash
7+
brew tap free-now/cli "https://github.com/freenowtech/git-jira.git"
8+
brew install free-now/cli/git-jira
9+
```
10+
11+
12+
Create a Personal Access Token (PAT) in **JIRA** (not Confluence ⚠️) as per [instruction](https://confluence.atlassian.com/enterprise/using-personal-access-tokens-1026032365.html#UsingPersonalAccessTokens-CreatingPATsintheapplication).
13+
14+
Add `$JIRA_PAT` and `$JIRA_INSTANCE` to your favorite shell:
15+
16+
```
17+
echo -n 'export JIRA_PAT=YOUR_PAT' >> ~/.zshrc
18+
echo -n 'export JIRA_INSTANCE=YOUR_JIRA_INSTANCE' >> ~/.zshrc
19+
source ~/.zshrc
20+
```
21+
22+
## Usage
23+
24+
Run with `git-jira` or `git jira`.
25+
26+
### Prefixing behavior
27+
28+
1. **Default:** `feature/SUP-1344-bla`
29+
30+
2. `--no-prefix` ➡️ `SUP-1344-bla`
31+
32+
3. `--prefix blubb` ➡️ `blubb/SUP-1344-bla`

SECURITY

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
We acknowledge that every line of code that we write may potentially contain security issues.
2+
3+
We are trying to deal with it responsibly and provide patches as quickly as possible. If you have anything to report to us please use the following channels:
4+
5+

git_jira/__init__.py

Whitespace-only changes.

git_jira/git_jira.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/usr/bin/env python
2+
import json
3+
import os
4+
import re
5+
import subprocess
6+
from urllib import request
7+
8+
import typer
9+
from simple_term_menu import TerminalMenu
10+
from typing_extensions import Annotated
11+
from typing import Optional
12+
13+
MAX_RESULT = 5
14+
15+
16+
def load_branches():
17+
instance = os.environ.get("JIRA_INSTANCE")
18+
token = os.environ.get("JIRA_PAT")
19+
if not instance:
20+
raise Exception("Please disclose your jira instance as $JIRA_INSTANCE")
21+
if not token:
22+
raise Exception("Please disclose your jira token as $JIRA_PAT")
23+
req = request.Request(
24+
instance + '/rest/api/2/search?'
25+
'jql=assignee=currentUser()+order+by+updated&fields=id,key,summary,issuetype,assignee',
26+
method="GET")
27+
req.add_header('Authorization', f'Bearer {token}')
28+
response = request.urlopen(req).read().decode('utf-8')
29+
response = json.loads(response)
30+
31+
formatted_branches = []
32+
33+
for issue in response['issues']:
34+
formatted = issue['key'] + " " + issue['fields']['summary']
35+
formatted_branches.append(re.sub(r"[^a-zA-Z0-9]+", ' ', formatted))
36+
return formatted_branches[:MAX_RESULT]
37+
38+
39+
def main(prefix: Annotated[str, typer.Option(help="Prefix that is being used for the new branch.")] = "feature",
40+
no_prefix: Annotated[bool, typer.Option("--no-prefix", help="Will not use a prefix")] = False):
41+
"""
42+
CLI to switch to git branches based on one's JIRA tickets.
43+
44+
If --prefix is used, it will add a specific prefix to the branch (e.g. feature -> "feature/")
45+
--no-prefix will omit the default "feature/" prefix.
46+
"""
47+
tasks = load_branches()
48+
terminal_menu = TerminalMenu(tasks)
49+
menu_entry_index = terminal_menu.show()
50+
selected_task = tasks[menu_entry_index]
51+
prefix = None if no_prefix else prefix
52+
formatted_branch = format_branch(selected_task, prefix)
53+
print(f"Switching to branch: {formatted_branch}")
54+
process = subprocess.Popen(['git', 'switch', '-c', formatted_branch],
55+
stdout=subprocess.PIPE)
56+
process.communicate()
57+
58+
59+
def format_branch(selected_task: str, prefix: Optional[str]):
60+
print(f"Using prefix: {prefix}")
61+
selected_task = re.sub(r'\s', '-',
62+
selected_task).lower()
63+
jira_key = re.match(r'[A-Za-z]{2,}-\d+', selected_task).group()
64+
selected_task = selected_task.replace(jira_key, jira_key.upper())
65+
formatted_branch = (f"{prefix}/" if prefix else '') + selected_task
66+
return formatted_branch
67+
68+
69+
if __name__ == "__main__":
70+
typer.run(main)

out.gif

194 KB
Loading

0 commit comments

Comments
 (0)