forked from pycontribs/jira
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasic_use.py
53 lines (40 loc) · 1.67 KB
/
basic_use.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# This script shows how to use the client in anonymous mode
# against jira.atlassian.com.
from __future__ import annotations
import re
from jira import JIRA
# By default, the client will connect to a Jira instance started from the Atlassian Plugin SDK
# (see https://developer.atlassian.com/display/DOCS/Installing+the+Atlassian+Plugin+SDK for details).
jira = JIRA(server="https://jira.atlassian.com")
# Get all projects viewable by anonymous users.
projects = jira.projects()
# Sort available project keys, then return the second, third, and fourth keys.
keys = sorted(project.key for project in projects)[2:5]
# Get an issue.
issue = jira.issue("JRA-1330")
# Find all comments made by Atlassians on this issue.
atl_comments = [
comment
for comment in issue.fields.comment.comments
if re.search(r"@atlassian.com$", comment.author.key)
]
# Add a comment to the issue.
jira.add_comment(issue, "Comment text")
# Change the issue's summary and description.
issue.update(
summary="I'm different!", description="Changed the summary to be different."
)
# Change the issue without sending updates
issue.update(notify=False, description="Quiet summary update.")
# You can update the entire labels field like this
issue.update(fields={"labels": ["AAA", "BBB"]})
# Or modify the List of existing labels. The new label is unicode with no
# spaces
issue.fields.labels.append("new_text")
issue.update(fields={"labels": issue.fields.labels})
# Send the issue away for good.
issue.delete()
# Linking a remote jira issue (needs applinks to be configured to work)
issue = jira.issue("JRA-1330")
issue2 = jira.issue("XX-23") # could also be another instance
jira.add_remote_link(issue.id, issue2)