setjcomment 1.1.1__py3-none-any.whl

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 @@
1
+ from .setjcomment import run
@@ -0,0 +1,83 @@
1
+ import requests
2
+ import os
3
+ import subprocess
4
+ import argparse
5
+ import sys
6
+ sys.stdout.reconfigure(encoding="utf-8")#type: ignore
7
+ sys.stderr.reconfigure(encoding="utf-8")#type: ignore
8
+ from requests.auth import HTTPBasicAuth
9
+ from datetime import date
10
+ from importlib import resources
11
+
12
+ JIRA_SERVER = os.getenv("JIRA_SERVER","")
13
+ USERNAME = os.getenv("JIRA_USERNAME","")
14
+ PASSWORD = os.getenv("JIRA_PASSWORD","")
15
+ TEMP_PATH = os.getenv("TEMP", "D:\\temp")
16
+ TRACKING_TITLE = "PERSONAL TRACKING"
17
+ TEMPLATE_FILE_NAME = "temp_comment.jira"
18
+ TODAY = date.today().strftime("%d/%m/%Y")
19
+ ISSUE_KEY = "SETV-%s"
20
+ EDITOR = "nvim"
21
+ URL = "https://{0}/rest/api/2/issue/{1}/comment"
22
+ HEADERS = {"Accept": "application/json","Content-Type": "application/json"}
23
+ PAYLOAD = {"body": ""}
24
+
25
+ def parse_args():
26
+ parser = argparse.ArgumentParser(description="Add a comment to a JIRA issue.")
27
+ parser.add_argument("issue_id", type=int, help="The ID of the JIRA issue (e.g., 6552 for SETV-6552).")
28
+ parser.add_argument("-s", "--short",required=False, default="", type=str, help="for add a short unformatted comment.")
29
+ parser.add_argument("-vs", "--VScode",action="store_true", default=False, help="Open the template file in VScode instead of nvim.")
30
+ parser.add_argument("-np", "--notepad", action="store_true", default=False, help="Open the template file in notepad instead of nvim.")
31
+ return parser.parse_args()
32
+
33
+ def create_payload(cwd: str, args:argparse.Namespace) -> dict[str, str]:
34
+ body = ""
35
+ with open(f"{cwd}\\{TEMPLATE_FILE_NAME}", "r") as f:
36
+ lines = f.readlines()
37
+ with open(f"{TEMP_PATH}\\{TEMPLATE_FILE_NAME}", "w") as outputfile:
38
+ outputfile.writelines(lines)
39
+ if args.short:
40
+ body = str(args.short).replace(";", "\n")
41
+ else:
42
+ if args.VScode:
43
+ proc = subprocess.Popen(["c:\\LegacyApp\\VScode\\Code.exe", f"{TEMP_PATH}\\{TEMPLATE_FILE_NAME}"], shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
44
+ proc.wait()
45
+ elif args.notepad:
46
+ subprocess.call(["notepad", f"{TEMP_PATH}\\{TEMPLATE_FILE_NAME}"])
47
+ else:
48
+ subprocess.call([EDITOR, f"{TEMP_PATH}\\{TEMPLATE_FILE_NAME}"])
49
+ with open(f"{TEMP_PATH}\\{TEMPLATE_FILE_NAME}", "r") as f:
50
+ additional_comment = f.read()
51
+ os.remove(f"{TEMP_PATH}\\{TEMPLATE_FILE_NAME}")
52
+ for line in additional_comment.splitlines():
53
+ if line.__contains__("::DATE::"):
54
+ line = line.replace("::DATE::", TODAY)
55
+ if line.__contains__("----"):
56
+ line = line+"\n"
57
+ body += line + "\n"
58
+ return {"body": body}
59
+
60
+ def connect_jira(payload: dict[str,str], args: argparse.Namespace):
61
+ url = URL.format(JIRA_SERVER, ISSUE_KEY % args.issue_id)
62
+ auth = HTTPBasicAuth(USERNAME, PASSWORD)
63
+ response = requests.post(url, auth=auth, headers=HEADERS, json=payload)
64
+ if response.status_code == 201:
65
+ print("Comment added successfully.")
66
+ else:
67
+ print("Failed to add comment. Status code:", response.status_code)
68
+ print("Response:", response.text)
69
+
70
+ def run() -> None:
71
+ text_path = resources.files("setjcomment").joinpath(TEMPLATE_FILE_NAME)
72
+ if not text_path.is_file():
73
+ print(f"Template file '{TEMPLATE_FILE_NAME}' not found in the package resources.")
74
+ return
75
+ path = str(text_path.parent)#type: ignore
76
+ args = parse_args()
77
+ print(f"Using template file at: {str(path)}")
78
+ payload = create_payload(str(path), args)
79
+ connect_jira(payload, args)
80
+
81
+ #This allows the script to be run directly, and also allows the 'run' function to be imported and used in other contexts (like testing).
82
+ if __name__ == "__main__":
83
+ run()
@@ -0,0 +1,13 @@
1
+ h1. ::DATE::
2
+ * Task1 - *0.0h*
3
+
4
+
5
+ ----
6
+
7
+ h1. Personal Tracking:
8
+
9
+ {quote}
10
+ TEXT
11
+ - Topic1: text
12
+ - Topic2: text
13
+ {quote}
@@ -0,0 +1,81 @@
1
+ Metadata-Version: 2.4
2
+ Name: setjcomment
3
+ Version: 1.1.1
4
+ Summary: A Jira comment management tool via terminal. Manage your JIRA issue comments directly from the terminal, using the REST API of JIRA. This tool allows you to add comments to JIRA issues using a template file for consistent formatting, and supports multiple editors for editing the comment content.
5
+ Author-email: Juan Jose Solorzano <juanjose.solorzano.c@gmail.com>
6
+ License-File: LICENSE
7
+ Requires-Python: >=3.8
8
+ Description-Content-Type: text/markdown
9
+
10
+ # setjcomment
11
+
12
+ > A Jira comment management tool via terminal. Manage your JIRA issue comments directly from the terminal, using the REST API of JIRA. This tool allows you to add comments to JIRA issues using a template file for consistent formatting, and supports multiple editors for editing the comment content.
13
+
14
+ `setjcomment` allows you to add comments to JIRA issues directly from your terminal, using a template file for consistent formatting.
15
+
16
+ ---
17
+
18
+ ## Features
19
+
20
+ - **Add comments to JIRA issues** directly from the terminal
21
+ - **Use a template file** for consistent comment formatting
22
+ - **Supports multiple editors** (nvim, VScode, Notepad)
23
+ - **Environment variable configuration** for JIRA server, username, and password
24
+ - Works as a global CLI command after installation
25
+
26
+ ---
27
+
28
+ ## Installation
29
+
30
+ ```bash
31
+ pip install setjcomment
32
+ ```
33
+
34
+ Or install from source:
35
+
36
+ ```bash
37
+ git clone https://github.com/your-username/setjcomment.git
38
+ cd setjcomment
39
+ pip install .
40
+ ```
41
+
42
+ ---
43
+
44
+ ## Dependencies
45
+ - [`Pygments`](https://pypi.org/project/Pygments/) for syntax highlighting
46
+ - [`colored`](https://pypi.org/project/colored/) for terminal color output
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
+ -s SHORT, --short SHORT
58
+ for add a short unformatted comment.
59
+ -vs, --VScode Open the template file in VScode instead of nvim.
60
+ -np, --notepad Open the template file in notepad instead of nvim.
61
+
62
+ ```
63
+
64
+ ### Examples
65
+
66
+ ```bash
67
+ setjcomment 6552 -s "This is a short comment."
68
+ setjcomment 6552 -vs # Opens the template file in VScode for editing.
69
+ setjcomment 6552 -np # Opens the template file in Notepad for editing.
70
+ ```
71
+ ---
72
+
73
+ ## License
74
+
75
+ See [LICENSE](LICENSE) for details.
76
+
77
+ ---
78
+
79
+ ## Author
80
+
81
+ **Juan Jose Solorzano Carrillo** — juanjose.solorzano.c@gmail.com
@@ -0,0 +1,8 @@
1
+ setjcomment/__init__.py,sha256=aJu3GsJRkiyXF70Xd7f1Qp0anCkUia0XgG6floXkxNI,28
2
+ setjcomment/setjcomment.py,sha256=d_iFDbp_HzYUT-gI_Ugbbt82EpeHxIO-w96aE65LB7o,3772
3
+ setjcomment/temp_comment.jira,sha256=cOlb2WOqVLXD7UWHABKIrRVnUV_lGbTI1MS8VDNAkwc,133
4
+ setjcomment-1.1.1.dist-info/METADATA,sha256=HoOmAWdSkoDUCyeJ2S2Q00G2ZOo6nzsMQdkmjTVOXsA,2438
5
+ setjcomment-1.1.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
6
+ setjcomment-1.1.1.dist-info/entry_points.txt,sha256=5aQht15dQPMyDjcZCURT35Qtov_qp_-owZvsL4IfM5s,60
7
+ setjcomment-1.1.1.dist-info/licenses/LICENSE,sha256=vbRFpJt-Pq08NNzDVziW2liD8zHdPfS9Nzkd0Z2Qg_Q,621
8
+ setjcomment-1.1.1.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.27.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ setjcomment = setjcomment.setjcomment:run
@@ -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.