getjticket 1.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,11 @@
1
+ Copyright (c) 2024 Juan Jose Solorzano Carrillo
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
@@ -0,0 +1,80 @@
1
+ Metadata-Version: 2.4
2
+ Name: getjticket
3
+ Version: 1.0.1
4
+ Summary: A tool to fetch and display JIRA ticket information in the terminal.
5
+ Author-email: Juan Jose Solorzano <juanjose.solorzano.c@gmail.com>
6
+ License-File: LICENSE
7
+ Requires-Python: >=3.8
8
+ Requires-Dist: colored>=1.4.4
9
+ Requires-Dist: pygments>=2.17.0
10
+ Description-Content-Type: text/markdown
11
+
12
+ # getjticket
13
+
14
+ > A Jira ticket information fetcher tool via terminal.
15
+
16
+ `getjticket` allows you to fetch and display JIRA ticket information directly from your terminal. This tool uses the REST API of JIRA to interact with your JIRA server, and requires environment variables for configuration.
17
+ ---
18
+
19
+ ## Features
20
+
21
+ - **Fetch JIRA ticket information** directly from the terminal
22
+ - **Display time tracking information** for JIRA issues
23
+ - **Display issue description** for JIRA issues
24
+ - **Environment variable configuration** for JIRA server, username, and password
25
+ - **Works as** a global CLI command after installation
26
+
27
+ ---
28
+
29
+ ## Installation
30
+
31
+ ```bash
32
+ pip install getjticket
33
+ ```
34
+
35
+ Or install from source:
36
+
37
+ ```bash
38
+ git clone https://github.com/JuanJoseSolorzano/getjticket_project.git
39
+ cd getjticket_project
40
+ pip install .
41
+ ```
42
+ ## Required Environment Variables
43
+ - `JIRA_SERVER`: The URL of your JIRA server (e.g., `yourdomain.atlassian.net`).
44
+ - `JIRA_USERNAME`: Your JIRA username (usually your email address).
45
+ - `JIRA_PASSWORD`: Your JIRA API token or password.
46
+ ---
47
+
48
+ ## Usage
49
+
50
+ ```bash
51
+
52
+ positional arguments:
53
+ issue_id The ID of the JIRA issue (e.g., 6552 for SETV-6552).
54
+
55
+ optional arguments:
56
+ -h, --help show this help message and exit
57
+
58
+ -t TIME, --time Shows the time tracking information for the JIRA issue in a pretty format [optional].
59
+ -d DESCRIPTION, --description Shows the description of the JIRA issue in a pretty format [optional].
60
+
61
+ NOTE: If no optional arguments are provided, the tool will display the issue summary and key by default.
62
+ ```
63
+
64
+ ### Examples
65
+
66
+ ```bash
67
+ getjticket 6552 -t "Time tracking information for the JIRA issue."
68
+ getjticket 6552 -d "Description of the JIRA issue."
69
+ ```
70
+ ---
71
+
72
+ ## License
73
+
74
+ See [LICENSE](LICENSE) for details.
75
+
76
+ ---
77
+
78
+ ## Author
79
+
80
+ **Juan Jose Solorzano Carrillo** — juanjose.solorzano.c@gmail.com
@@ -0,0 +1,69 @@
1
+ # getjticket
2
+
3
+ > A Jira ticket information fetcher tool via terminal.
4
+
5
+ `getjticket` allows you to fetch and display JIRA ticket information directly from your terminal. This tool uses the REST API of JIRA to interact with your JIRA server, and requires environment variables for configuration.
6
+ ---
7
+
8
+ ## Features
9
+
10
+ - **Fetch JIRA ticket information** directly from the terminal
11
+ - **Display time tracking information** for JIRA issues
12
+ - **Display issue description** for JIRA issues
13
+ - **Environment variable configuration** for JIRA server, username, and password
14
+ - **Works as** a global CLI command after installation
15
+
16
+ ---
17
+
18
+ ## Installation
19
+
20
+ ```bash
21
+ pip install getjticket
22
+ ```
23
+
24
+ Or install from source:
25
+
26
+ ```bash
27
+ git clone https://github.com/JuanJoseSolorzano/getjticket_project.git
28
+ cd getjticket_project
29
+ pip install .
30
+ ```
31
+ ## Required Environment Variables
32
+ - `JIRA_SERVER`: The URL of your JIRA server (e.g., `yourdomain.atlassian.net`).
33
+ - `JIRA_USERNAME`: Your JIRA username (usually your email address).
34
+ - `JIRA_PASSWORD`: Your JIRA API token or password.
35
+ ---
36
+
37
+ ## Usage
38
+
39
+ ```bash
40
+
41
+ positional arguments:
42
+ issue_id The ID of the JIRA issue (e.g., 6552 for SETV-6552).
43
+
44
+ optional arguments:
45
+ -h, --help show this help message and exit
46
+
47
+ -t TIME, --time Shows the time tracking information for the JIRA issue in a pretty format [optional].
48
+ -d DESCRIPTION, --description Shows the description of the JIRA issue in a pretty format [optional].
49
+
50
+ NOTE: If no optional arguments are provided, the tool will display the issue summary and key by default.
51
+ ```
52
+
53
+ ### Examples
54
+
55
+ ```bash
56
+ getjticket 6552 -t "Time tracking information for the JIRA issue."
57
+ getjticket 6552 -d "Description of the JIRA issue."
58
+ ```
59
+ ---
60
+
61
+ ## License
62
+
63
+ See [LICENSE](LICENSE) for details.
64
+
65
+ ---
66
+
67
+ ## Author
68
+
69
+ **Juan Jose Solorzano Carrillo** — juanjose.solorzano.c@gmail.com
@@ -0,0 +1,21 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "getjticket"
7
+ version = "1.0.1"
8
+ authors = [
9
+ { name="Juan Jose Solorzano", email="juanjose.solorzano.c@gmail.com" }
10
+ ]
11
+ description = "A tool to fetch and display JIRA ticket information in the terminal."
12
+ readme = "README.md"
13
+ requires-python = ">=3.8"
14
+ dependencies = [
15
+ "pygments>=2.17.0",
16
+ "colored>=1.4.4"
17
+ ]
18
+
19
+ # Right side: package_folder.module_file:function_name
20
+ [project.scripts]
21
+ getjticket = "getjticket.getjticket:run" # Creates the global 'getjticket' terminal command!
File without changes
@@ -0,0 +1,127 @@
1
+ import requests
2
+ import os
3
+ import argparse
4
+ import re
5
+ import sys
6
+ sys.stdout.reconfigure(encoding="utf-8")#type: ignore
7
+ sys.stderr.reconfigure(encoding="utf-8")#type: ignore
8
+ from colored import Fore,Style
9
+ from requests.auth import HTTPBasicAuth
10
+ from pygments import highlight
11
+ from pygments.lexers import TextLexer, get_lexer_by_name
12
+ from pygments.formatters import TerminalTrueColorFormatter
13
+ from datetime import date
14
+
15
+ JIRA_SERVER = os.getenv("JIRA_SERVER","")
16
+ USERNAME = os.getenv("JIRA_USERNAME","")
17
+ PASSWORD = os.getenv("JIRA_PASSWORD","")
18
+ TODAY = date.today().strftime("%d/%m/%Y")
19
+ ISSUE_KEY = "SETV-%s"
20
+ URL = "https://{0}/rest/api/2/issue/{1}/comment"
21
+ HEADERS = {"Accept": "application/json","Content-Type": "application/json"}
22
+ PAYLOAD = {"body": ""}
23
+ SEPARATOR = '─' * 100
24
+ SEPARATOR_2 = '═' * 100
25
+ PINK = Fore.rgb("100%", "0%", "60%")
26
+ GRAY = Fore.rgb("50%", "50%", "50%")
27
+ PARAMS = {"fields": "summary,description,timespent,timeestimate,timetracking,worklog"}
28
+
29
+
30
+ def parse_args():
31
+ parser = argparse.ArgumentParser(description="Add a comment to a JIRA issue.")
32
+ parser.add_argument("issue_id", type=int, help="The ID of the JIRA issue (e.g., 6552 for SETV-6552).")
33
+ parser.add_argument("-d", "--description", action="store_true", default=False, help="Show detailed information about the issue.")
34
+ parser.add_argument("-t", "--time", action="store_true", default=False, help="Show time tracking information for the issue.")
35
+ return parser.parse_args()
36
+
37
+ def markup2markdown(text):
38
+ # Remove separators
39
+ text = re.sub(r'^[-=]{4,}\s*$', '', text, flags=re.MULTILINE)
40
+ # Headings: h1. text -> # text
41
+ for i in range(1, 7):
42
+ text = re.sub(rf'^h{i}\.\s*(.*)$', lambda m: f"{'#' * i} {m.group(1)}", text, flags=re.MULTILINE)
43
+ # Bullet points
44
+ text = re.sub(r'^\s*\*\s+', '- ', text, flags=re.MULTILINE)
45
+ # Blockquotes
46
+ text = re.sub(r'^\s*>\s?', '> ', text, flags=re.MULTILINE)
47
+ # Bold: *text* -> **text**
48
+ text = re.sub(r'\*(.*?)\*', r'**\1**', text)
49
+ # Italic: _text_ -> _text_
50
+ text = re.sub(r'_(.*?)_', r'_\1_', text)
51
+ # Inline code: {{code}} -> `code`
52
+ text = re.sub(r'\{\{(.*?)\}\}', r'`\1`', text)
53
+ # Clean extra blank lines
54
+ text = re.sub(r'\n{3,}', '\n\n', text)
55
+ return text.strip()
56
+
57
+ def connect_jira(issue_id:str) -> requests.Response:
58
+ url = f"https://{JIRA_SERVER}/rest/api/2/issue/{ISSUE_KEY % issue_id}"
59
+ return requests.get(
60
+ url,
61
+ params=PARAMS,
62
+ auth=HTTPBasicAuth(USERNAME, PASSWORD),
63
+ headers={"Accept": "application/json"}
64
+ )
65
+
66
+ def get_time_tracking_info(fields, linK_to_issue, issue_id) -> None:
67
+ worklogs = fields["worklog"]["worklogs"]
68
+ estimated = fields["timetracking"]["originalEstimate"]
69
+ remaining = fields["timetracking"]["remainingEstimate"]
70
+ try:
71
+ time_spent = fields["timetracking"]["timeSpent"]
72
+ except KeyError:
73
+ time_spent = "0s"
74
+ print(SEPARATOR)
75
+ print(f"Issue ID: {ISSUE_KEY % issue_id}")
76
+ print(f"Summary: {fields['summary']}")
77
+ print(f"Link to Issue: {linK_to_issue}")
78
+ print(" ")
79
+ print(f"{'':<25}[- TIME TRACKING INFORMATION -]")
80
+ print(" ")
81
+ print(f"{'Original Estimate:':<20} {estimated}")
82
+ print(f"{'Remaining Time:':<20} {remaining}")
83
+ print(f"{'Time Spent:':<20} {time_spent}")
84
+
85
+ print(SEPARATOR_2)
86
+ print(f"{'Author':<25} {'Started':<20} {'Time Spent':<12} Comment")
87
+ print(SEPARATOR)
88
+
89
+ for worklogged in worklogs:
90
+ author = worklogged["author"]["displayName"]
91
+ time_spent = worklogged["timeSpent"]
92
+ started = worklogged["started"].replace("T", " ").replace(".000+0000", "")
93
+ comment = worklogged.get("comment", "")
94
+ comment = comment[:50] + "..." if len(comment) > 50 else comment
95
+ print(f"{author:<25} {started:<20} {time_spent:<12} {comment}")
96
+ print(SEPARATOR_2)
97
+
98
+ def get_description(fields, linK_to_issue, issue_id) -> None:
99
+ description = fields.get("description", "No description provided.")
100
+ cleaned = markup2markdown(description)
101
+ lexer = get_lexer_by_name("markdown", stripall=True)
102
+ colored_output = highlight(cleaned, lexer, TerminalTrueColorFormatter()).splitlines()
103
+ print(SEPARATOR_2)
104
+ print(f" {GRAY}{ISSUE_KEY % issue_id} - {fields['summary']}")
105
+ print(f" [{linK_to_issue}]{Style.reset}")
106
+ print(f"{SEPARATOR}")
107
+ for line_number, line in enumerate(colored_output, start=1):
108
+ print(f"{GRAY}{line_number:<2}│ {Style.reset}{line}")
109
+ print(SEPARATOR_2)
110
+
111
+ def run()->None:
112
+ args = parse_args()
113
+ issue_id = args.issue_id
114
+ linK_to_issue = f"https://{JIRA_SERVER}/browse/{ISSUE_KEY % issue_id}"
115
+ response = connect_jira(issue_id).json()
116
+ fields = response["fields"]
117
+ if args.description:
118
+ get_description(fields, linK_to_issue, issue_id)
119
+ elif args.time:
120
+ get_time_tracking_info(fields, linK_to_issue, issue_id)
121
+ else:
122
+ get_description(fields, linK_to_issue, issue_id)
123
+ get_time_tracking_info(fields, linK_to_issue, issue_id)
124
+
125
+ if __name__ == "__main__":
126
+ run()
127
+