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

Update README.rst with azure pipeline badge #3

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
64 changes: 64 additions & 0 deletions .github/workflows/jira_cloud_ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Jira Cloud CI

on:
workflow_run:
workflows: ["Jira Server CI"]
types:
- completed

jobs:
test:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
name: ${{ matrix.os }} / Python ${{ matrix.python-version }}
runs-on: ${{ matrix.os }}-latest
strategy:
matrix:
os: [Ubuntu]
# We only test a single version to prevent concurrent
# running of tests influencing one another
python-version: [3.8]

steps:
- uses: actions/checkout@master

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Get pip cache dir
id: pip-cache
run: |
echo "::set-output name=dir::$(pip cache dir)"
- name: Setup the Pip cache
uses: actions/cache@v2
with:
path: ${{ steps.pip-cache.outputs.dir }}
key: >-
${{ runner.os }}-pip-${{ hashFiles('setup.cfg') }}-${{
hashFiles('setup.py') }}-${{ hashFiles('tox.ini') }}-${{
hashFiles('.pre-commit-config.yaml') }}
restore-keys: |
${{ runner.os }}-pip-
${{ runner.os }}-

- name: Install Dependencies
run: |
sudo apt-get update; sudo apt-get install gcc libkrb5-dev
python -m pip install --upgrade pip
python -m pip install --upgrade tox tox-gh-actions

- name: Test with tox
run: tox -e py38 -- -m allow_on_cloud
env:
CI_JIRA_TYPE: CLOUD
CI_JIRA_CLOUD_ADMIN: ${{ secrets.CI_JIRA_CLOUD_ADMIN }}
CI_JIRA_CLOUD_ADMIN_TOKEN: ${{ secrets.CI_JIRA_CLOUD_ADMIN_TOKEN }}
CI_JIRA_CLOUD_USER: ${{ secrets.CI_JIRA_CLOUD_USER }}
CI_JIRA_CLOUD_USER_TOKEN: ${{ secrets.CI_JIRA_CLOUD_USER_TOKEN }}

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1.0.15
with:
file: ./coverage.xml
name: ${{ runner.os }}-${{ matrix.python-version }}-Cloud
4 changes: 4 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ Jira Python Library
:target: https://requires.io/github/pycontribs/jira/requirements/?branch=master
:alt: Requirements Status

.. image:: https://dev.azure.com/adehadd/adehad_jira/_apis/build/status/adehad.jira?branchName=master&label=Jira%20Cloud%20Pipeline
:target: https://dev.azure.com/adehadd/adehad_jira/_build/latest?definitionId=1&branchName=master
:alt: Jira Cloud Build Status


This library eases the use of the Jira REST API from Python and it has been used in production for years.

Expand Down
34 changes: 34 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Python package
# Create and test a Python package on multiple Python versions.
# Add steps that analyze code, save the dist with the build record, publish to a PyPI-compatible index, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/python

trigger:
- master

pool:
vmImage: ubuntu-latest
strategy:
matrix:
Python38:
python.version: '3.8'


steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '$(python.version)'
displayName: 'Use Python $(python.version)'

- script: |
sudo apt-get update; sudo apt-get install gcc libkrb5-dev
python -m pip install --upgrade pip
pip install tox
displayName: 'Install dependencies'

- script: |
tox -e py38 -- -m allow_on_cloud
displayName: 'tox'
env:
CI_JIRA_CLOUD_ADMIN_TOKEN: $(CI_JIRA_CLOUD_ADMIN_TOKEN)
CI_JIRA_CLOUD_USER_TOKEN: $(CI_JIRA_CLOUD_USER_TOKEN)
34 changes: 21 additions & 13 deletions jira/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3752,10 +3752,14 @@ def backup_download(self, filename: str = None):
self.log.error(ioe)
return None

def current_user(self, field: str = "key") -> str:
def current_user(self, field: Optional[str] = None) -> str:
"""Returns the username or emailAddress of the current user. For anonymous
users it will return a value that evaluates as False.

Args:
field (Optional[str]): the name of the identifier field.
Defaults to "accountId" for Jira Cloud, else "key"

Returns:
str
"""
Expand All @@ -3767,6 +3771,9 @@ def current_user(self, field: str = "key") -> str:
r_json: Dict[str, str] = json_loads(r)
self._myself = r_json

if field is None:
field = "accountId" if self._is_cloud else "key"

return self._myself[field]

def delete_project(self, pid: Union[str, Project]) -> Optional[bool]:
Expand Down Expand Up @@ -3966,31 +3973,31 @@ def create_project(

ps_list: List[Dict[str, Any]]

if not permissionScheme:
if permissionScheme is None:
ps_list = self.permissionschemes()
for sec in ps_list:
if sec["name"] == "Default Permission Scheme":
permissionScheme = sec["id"]
break
if not permissionScheme:
break
if permissionScheme is None and ps_list:
permissionScheme = ps_list[0]["id"]

if not issueSecurityScheme:
if issueSecurityScheme is None:
ps_list = self.issuesecurityschemes()
for sec in ps_list:
if sec["name"] == "Default": # no idea which one is default
issueSecurityScheme = sec["id"]
break
if not issueSecurityScheme and ps_list:
break
if issueSecurityScheme is None and ps_list:
issueSecurityScheme = ps_list[0]["id"]

if not projectCategory:
if projectCategory is None:
ps_list = self.projectcategories()
for sec in ps_list:
if sec["name"] == "Default": # no idea which one is default
projectCategory = sec["id"]
break
if not projectCategory and ps_list:
break
if projectCategory is None and ps_list:
projectCategory = ps_list[0]["id"]
# <beep> Atlassian for failing to provide an API to get projectTemplateKey values
# Possible values are just hardcoded and obviously depending on Jira version.
Expand All @@ -4000,7 +4007,9 @@ def create_project(
if not template_name:
# https://confluence.atlassian.com/jirakb/creating-projects-via-rest-api-in-jira-963651978.html
template_key = (
"com.pyxis.greenhopper.jira:basic-software-development-template"
"com.pyxis.greenhopper.jira:gh-simplified-basic"
if self._is_cloud
else "com.pyxis.greenhopper.jira:basic-software-development-template"
)

# https://developer.atlassian.com/cloud/jira/platform/rest/v2/api-group-projects/#api-rest-api-2-project-get
Expand Down Expand Up @@ -4063,8 +4072,7 @@ def create_project(
"key": key,
"projectTypeKey": ptype,
"projectTemplateKey": template_key,
"lead": assignee,
# "leadAccountId": assignee,
"leadAccountId" if self._is_cloud else "lead": assignee,
"assigneeType": "PROJECT_LEAD",
"description": "",
# "avatarId": 13946,
Expand Down
5 changes: 5 additions & 0 deletions make_local_jira_user.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Attempts to create a test user,
as the empty JIRA instance isn't provisioned with one.
"""
import sys
import time
from os import environ

Expand Down Expand Up @@ -29,6 +30,10 @@ def add_user_to_jira():


if __name__ == "__main__":
if environ.get("CI_JIRA_TYPE", "Server").upper() == "CLOUD":
print("Do not need to create a user for Jira Cloud CI, quitting.")
sys.exit()

start_time = time.time()
timeout_mins = 15
print(
Expand Down
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -160,5 +160,8 @@ timeout = 80
filterwarnings =
ignore::pytest.PytestWarning

markers =
allow_on_cloud: opt in for the test to run on Jira Cloud

[mypy]
python_version = 3.6
Loading