59 lines
2.1 KiB
Python
Executable File
59 lines
2.1 KiB
Python
Executable File
from ssl import SSLCertVerificationError
|
|
import requests
|
|
from requests.auth import HTTPBasicAuth
|
|
import json
|
|
from dotenv import load_dotenv
|
|
import os
|
|
|
|
# Before running the script make sure the following:
|
|
# 1. The correct root certificate is in the script directory and specified
|
|
# under the global variables
|
|
# 2. You've created the .env file with the following format:
|
|
# JIRA_USER=<your username>
|
|
# JIRA_PASSWORD=<your password>
|
|
# 3. You have installed necessary packages from the requirements.txt file
|
|
|
|
load_dotenv()
|
|
|
|
JIRA_URL = 'https://globaljira.roche.com/rest/api/2/issue/picker'
|
|
USERNAME = os.getenv("JIRA_USER")
|
|
PASSWORD = os.getenv("JIRA_PASSWORD")
|
|
ROOT_CERT = ".\\Roche G3 Root CA.crt"
|
|
PRINT_RESPONSE_ON_ERR = False
|
|
|
|
headers = {
|
|
'Content-Type': 'application/json'
|
|
}
|
|
|
|
# For this query for user kalinom6 there are 6 results, 5 of them are correct,
|
|
# but one is certainly not associated with the user in any way according to
|
|
# the web application. The result set is lacking too, there should be way
|
|
# more issues assigned to this user
|
|
query = {
|
|
'query': f'assignee = {USERNAME} AND status not in (Closed, Done)'
|
|
}
|
|
|
|
print(f'{USERNAME}, {PASSWORD}')
|
|
|
|
try:
|
|
response = requests.get(
|
|
JIRA_URL,
|
|
auth=HTTPBasicAuth(USERNAME, PASSWORD),
|
|
headers=headers,
|
|
params=query,
|
|
verify=ROOT_CERT
|
|
)
|
|
except SSLCertVerificationError:
|
|
print("SSL verification failed. Please make sure you're connected to the VPN and the correct root certificate is included.")
|
|
|
|
if response.status_code == 200:
|
|
print("JQL query executed successfully!")
|
|
issues = json.dumps(json.loads(response.text), sort_keys=True, indent=4, separators=(",", ": "))
|
|
print(issues)
|
|
else:
|
|
print(f"Failed to execute JQL query. Status code: {response.status_code}")
|
|
if response.status_code == 403:
|
|
print("If you're sure you've set up the environment variables correctly\n \
|
|
Please login to Jira in the browser to solve a CAPTCHA.")
|
|
if PRINT_RESPONSE_ON_ERR:
|
|
print("Response:", response.text) |