Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
6
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
IGitt
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
34
Issues
34
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
10
Merge Requests
10
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Test Cases
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gitmate
open-source
IGitt
Commits
439ee8ec
Commit
439ee8ec
authored
Mar 23, 2018
by
Naveen Kumar Sangi
👽
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Comment: Implement JiraComment
parent
44c88d77
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
336 additions
and
0 deletions
+336
-0
IGitt/Jira/JiraComment.py
IGitt/Jira/JiraComment.py
+118
-0
tests/Jira/cassettes/JiraCommentTest.test_body.yaml
tests/Jira/cassettes/JiraCommentTest.test_body.yaml
+53
-0
tests/Jira/cassettes/JiraCommentTest.test_body_setter.yaml
tests/Jira/cassettes/JiraCommentTest.test_body_setter.yaml
+55
-0
tests/Jira/cassettes/JiraCommentTest.test_time.yaml
tests/Jira/cassettes/JiraCommentTest.test_time.yaml
+54
-0
tests/Jira/test_jira_comment.py
tests/Jira/test_jira_comment.py
+56
-0
No files found.
IGitt/Jira/JiraComment.py
0 → 100644
View file @
439ee8ec
"""
Represents the comment resource from JIRA.
"""
from
datetime
import
datetime
from
typing
import
Union
from
IGitt.Interfaces
import
delete
from
IGitt.Interfaces
import
put
from
IGitt.Interfaces
import
BasicAuthorizationToken
from
IGitt.Interfaces.Comment
import
Comment
from
IGitt.Interfaces.Comment
import
CommentType
from
IGitt.Interfaces.User
import
User
from
IGitt.Jira
import
JiraMixin
from
IGitt.Jira
import
JiraOAuth1Token
class
JiraComment
(
JiraMixin
,
Comment
):
"""
Represents a comment on JIRA, mainly with a body and author - oh and it's
deletable!
"""
def
__init__
(
self
,
token
:
Union
[
BasicAuthorizationToken
,
JiraOAuth1Token
],
issue_id
:
Union
[
int
,
str
],
comment_id
:
int
):
"""
Instantiates a new JiraComment instance from the given data.
:param token:
The token to be used for authentication.
:param issue_id:
The unique identifier or key for the issue on JIRA.
:param comment_id:
The unique identifier of the comment on JIRA.
"""
self
.
_token
=
token
self
.
_id
=
comment_id
self
.
_issue
=
issue_id
self
.
_url
=
'/issue/{}/comment/{}'
.
format
(
self
.
_issue
,
self
.
_id
)
@
property
def
number
(
self
)
->
int
:
"""
Retrieves the id of the comment.
"""
return
self
.
_id
@
property
def
type
(
self
)
->
CommentType
:
"""
Retrieves the type of the comment it links to.
"""
return
CommentType
.
ISSUE
@
property
def
body
(
self
):
"""
Retrieves the content of the comment:
:return: A string containing the body.
"""
return
self
.
data
[
'body'
]
@
body
.
setter
def
body
(
self
,
new_body
:
str
):
"""
Modifies the comment body to ``new_body``.
:param new_body: A string containing comment body.
"""
payload
=
{
'body'
:
new_body
}
self
.
data
=
put
(
self
.
_token
,
self
.
url
,
payload
)
@
property
def
author
(
self
)
->
User
:
"""
Retrieves the author of the comment.
:return: A User object.
"""
raise
NotImplementedError
@
property
def
created
(
self
)
->
datetime
:
"""
Retrieves a timestamp on when the comment was created.
:return: A datetime.datetime object representing the time of
creation of the comment.
"""
return
datetime
.
strptime
(
self
.
data
[
'created'
],
'%Y-%m-%dT%H:%M:%S.%f%z'
)
@
property
def
updated
(
self
)
->
datetime
:
"""
Retrieves a timestamp on when the comment was updated the last time.
:return: A datetime.datetime object representing the time of the
last update of the comment.
"""
return
datetime
.
strptime
(
self
.
data
[
'updated'
],
'%Y-%m-%dT%H:%M:%S.%f%z'
)
def
delete
(
self
):
"""
Deletes the comment.
"""
delete
(
self
.
_token
,
self
.
url
)
@
property
def
repository
(
self
):
"""
Returns the JIRA project this comment was posted in, as a
JiraRepository instance.
"""
raise
NotImplementedError
tests/Jira/cassettes/JiraCommentTest.test_body.yaml
0 → 100644
View file @
439ee8ec
interactions
:
-
request
:
body
:
'
{}'
headers
:
Accept
:
-
!!binary
|
Ki8q
Accept-Encoding
:
-
!!binary
|
Z3ppcCwgZGVmbGF0ZQ==
Connection
:
-
!!binary
|
a2VlcC1hbGl2ZQ==
Content-Length
:
[
'
2'
]
Content-Type
:
-
!!binary
|
YXBwbGljYXRpb24vanNvbg==
User-Agent
:
-
!!binary
|
SUdpdHQ=
method
:
GET
uri
:
https://jira.gitmate.io/rest/api/2/issue/10001/comment/10001?per_page=100
response
:
body
:
string
:
!!binary
|
H4sIAAAAAAAAAOyUS2vcMBDHv4rQoZc41mMdr9ewJJu0p9JemlxKIGit8VpZyzJ67IOQ714p7osQ
KIU95iI0f41+M2L+6Ak76Ftc48770dWEPCor8o3yWnjIlSEWnCdiVIQT5VwAwiiljDRGaxj8FOEM
KxkZvwIRfGcsrp/+Ax4c2Mu0DELD8hi26kG5h7WxICMxiZHzWt7C8Q0VtFD9SspIdz+Pr/4UTf3t
hBf2zvYu9VhUh6L6q8n9fp9v7JSTx3eSaUtAgmgXbC6Ldl62i9mar5u2ZO0FXYAsgV7KpdYf3DLC
MsyLAy9OCI2wDLPywMoTQiMswzN+mPETQiPsOcNSubEXx6/T3L6ETmgtJPoslBMWrey2E0OaROPV
LmZ4GyDDXmn4boZ045NvyN3tTUKtjUxTvrEQBygRQ1IcHRIbc2/vh2vRbHuzQd6gb9BDkzJaY9FH
2EFvxuRRdIE6E6xDjCOthuDh5XasHkYZkat3t7679WRubSabRpFTVp3T2Tkrb2lV06Lm83xRVmfx
k6S/zffPxOcfAAAA//8DAPbolYeiBQAA
headers
:
Cache-Control
:
[
'
no-cache,
no-store,
no-transform'
]
Content-Encoding
:
[
gzip
]
Content-Length
:
[
'
423'
]
Content-Security-Policy
:
[
frame-ancestors 'self'
]
Content-Type
:
[
application/json;charset=UTF-8
]
Date
:
[
'
Fri,
23
Mar
2018
13:26:05
GMT'
]
Set-Cookie
:
[
JSESSIONID=0333AC2A25040CA2E8F8CFAA4C2540FB;path=/;HttpOnly
,
atlassian.xsrf.token=B15V-IRV7-Q0YS-ZCZZ|0d83180fc0d3740d23d2efa3bc587db1beee81ea|lin;path=/
]
Strict-Transport-Security
:
[
max-age=315569260; preload
]
Vary
:
[
User-Agent
]
X-Arequestid
:
[
806x7133x1
]
X-Asen
:
[
SEN-L11373089
]
X-Asessionid
:
[
1vajkol
]
X-Ausername
:
[
nkprince007
]
X-Content-Type-Options
:
[
nosniff
]
X-Frame-Options
:
[
DENY
,
SAMEORIGIN
]
X-Seraph-Loginreason
:
[
OK
]
X-Xss-Protection
:
[
1; mode=block
,
1; mode=block
]
status
:
{
code
:
200
,
message
:
OK
}
version
:
1
tests/Jira/cassettes/JiraCommentTest.test_body_setter.yaml
0 → 100644
View file @
439ee8ec
interactions
:
-
request
:
body
:
'
{"body":
"test
comment
body
has
changed"}'
headers
:
Accept
:
-
!!binary
|
Ki8q
Accept-Encoding
:
-
!!binary
|
Z3ppcCwgZGVmbGF0ZQ==
Connection
:
-
!!binary
|
a2VlcC1hbGl2ZQ==
Content-Length
:
[
'
41'
]
Content-Type
:
-
!!binary
|
YXBwbGljYXRpb24vanNvbg==
User-Agent
:
-
!!binary
|
SUdpdHQ=
method
:
PUT
uri
:
https://jira.gitmate.io/rest/api/2/issue/10001/comment/10001
response
:
body
:
string
:
!!binary
|
H4sIAAAAAAAAAKyUS2+cMBRG/wryopsQ/GI8gDRKR1VXUbPpZJNN5MFmcMGAbDMPRfnvtUPaPBRV
M81sEL5cjq/1HfkBWNlWoAC1c4MtIPylDE82ymnuZKJ6aKR1kA8KEqisHSXECCEMy15r2blpBWKg
hGf8WfDR1b0BxcMJ8NFKcxUeHddycRgbda/s/bo3UnhiKHrO+3IjDx9UpeaqXQrh6fb589eXTcN8
W+64uTWtDTOm2T7NXg252+2SjZl6En9OOL1CKSSvcjwXaTVnVU7XZF1WDFczlEvBJLoSC62/2IWH
xYCke5KeEephMcBsj9kZoR4WA0r2lJwR6mGPMRDKDi0/3Ey5/RhrrjUX0TVXlptoaZqadyGJ0qmt
73BmlDFwSsu7vgt/fHclvF19C6h1L0LKzrsSPWsXhVpUcxuVnrN5Sn0chA94+Wn1umYwqislQvMX
8d4WJ+3e1t5J1/GtlF1i/XRnkS9DBM9yWnHBZmTGM8xShtFaVBnOaEXof8l3LPQk+Y6FniTfsdCP
5Lt5iiL6GaL4l3JLqzi87tvG7xgopZE+tHCvEYSzS0QvMVuhrEBpQeZJzrILf92hv+a9biR0hWlB
WIFRgiidGh9/AwAA//8DAHs5VCBsBQAA
headers
:
Cache-Control
:
[
'
no-cache,
no-store,
no-transform'
]
Content-Encoding
:
[
gzip
]
Content-Length
:
[
'
480'
]
Content-Security-Policy
:
[
frame-ancestors 'self'
]
Content-Type
:
[
application/json;charset=UTF-8
]
Date
:
[
'
Fri,
23
Mar
2018
13:26:10
GMT'
]
Location
:
[
'
https://jira.gitmate.io/rest/api/2/issue/10001/comment/10001'
]
Set-Cookie
:
[
JSESSIONID=E0D51E209AE17030C16B5F8E359B0AFF;path=/;HttpOnly
,
atlassian.xsrf.token=B15V-IRV7-Q0YS-ZCZZ|15f593a72d2e331a44767632f0d46f39ef9bebb4|lin;path=/
]
Strict-Transport-Security
:
[
max-age=315569260; preload
]
Vary
:
[
User-Agent
]
X-Arequestid
:
[
806x7134x1
]
X-Asen
:
[
SEN-L11373089
]
X-Asessionid
:
[
kshq35
]
X-Ausername
:
[
nkprince007
]
X-Content-Type-Options
:
[
nosniff
]
X-Frame-Options
:
[
DENY
,
SAMEORIGIN
]
X-Seraph-Loginreason
:
[
OK
]
X-Xss-Protection
:
[
1; mode=block
,
1; mode=block
]
status
:
{
code
:
200
,
message
:
OK
}
version
:
1
tests/Jira/cassettes/JiraCommentTest.test_time.yaml
0 → 100644
View file @
439ee8ec
interactions
:
-
request
:
body
:
'
{}'
headers
:
Accept
:
-
!!binary
|
Ki8q
Accept-Encoding
:
-
!!binary
|
Z3ppcCwgZGVmbGF0ZQ==
Connection
:
-
!!binary
|
a2VlcC1hbGl2ZQ==
Content-Length
:
[
'
2'
]
Content-Type
:
-
!!binary
|
YXBwbGljYXRpb24vanNvbg==
User-Agent
:
-
!!binary
|
SUdpdHQ=
method
:
GET
uri
:
https://jira.gitmate.io/rest/api/2/issue/10001/comment/10001?per_page=100
response
:
body
:
string
:
!!binary
|
H4sIAAAAAAAAAKyUS2+cMBRG/wryopsQ/GI8gDRKR1VXUbPpZJNN5MFmcMGAbDMPRfnvtUPaPBRV
M81sEL5cjq/1HfkBWNlWoAC1c4MtIPylDE82ymnuZKJ6aKR1kA8KEqisHSXECCEMy15r2blpBWKg
hGf8WfDR1b0BxcMJ8NFKcxUeHddycRgbda/s/bo3UnhiKHrO+3IjDx9UpeaqXQrh6fb589eXTcN8
W+64uTWtDTOm2T7NXg252+2SjZl6En9OOL1CKSSvcjwXaTVnVU7XZF1WDFczlEvBJLoSC62/2IWH
xYCke5KeEephMcBsj9kZoR4WA0r2lJwR6mGPMRDKDi0/3Ey5/RhrrjUX0TVXlptoaZqadyGJ0qmt
73BmlDFwSsu7vgt/fHclvF19C6h1L0LKzrsSPWsXhVpUcxuVnrN5Sn0chA94+Wn1umYwqislQvMX
8d4WJ+3e1t5J1/GtlF1i/XRnkS9DBM9yWnHBZmTGM8xShtFaVBnOaEXof8l3LPQk+Y6FniTfsdCP
5Lt5iiL6GaL4l3JLqzi87tvG7xgopZE+tHCvEYSzS0QvMVuhrEBpQeZJzrILf92hv+a9biR0hWlB
WIFRgiidGh9/AwAA//8DAHs5VCBsBQAA
headers
:
Cache-Control
:
[
'
no-cache,
no-store,
no-transform'
]
Content-Encoding
:
[
gzip
]
Content-Length
:
[
'
480'
]
Content-Security-Policy
:
[
frame-ancestors 'self'
]
Content-Type
:
[
application/json;charset=UTF-8
]
Date
:
[
'
Fri,
23
Mar
2018
13:26:14
GMT'
]
Set-Cookie
:
[
JSESSIONID=8E3C855DE3EA8977F4329A7B467214ED;path=/;HttpOnly
,
atlassian.xsrf.token=B15V-IRV7-Q0YS-ZCZZ|81a00b6fa99ef1f98811ad4fcf1764e254702fff|lin;path=/
]
Strict-Transport-Security
:
[
max-age=315569260; preload
]
Vary
:
[
User-Agent
]
X-Arequestid
:
[
806x7135x1
]
X-Asen
:
[
SEN-L11373089
]
X-Asessionid
:
[
o3vpdg
]
X-Ausername
:
[
nkprince007
]
X-Content-Type-Options
:
[
nosniff
]
X-Frame-Options
:
[
DENY
,
SAMEORIGIN
]
X-Seraph-Loginreason
:
[
OK
]
X-Xss-Protection
:
[
1; mode=block
,
1; mode=block
]
status
:
{
code
:
200
,
message
:
OK
}
version
:
1
tests/Jira/test_jira_comment.py
0 → 100644
View file @
439ee8ec
import
os
import
datetime
import
requests_mock
from
IGitt.Jira
import
JiraOAuth1Token
from
IGitt.Jira.JiraComment
import
JiraComment
from
IGitt.Interfaces.Comment
import
CommentType
from
tests
import
IGittTestCase
class
JiraCommentTest
(
IGittTestCase
):
def
setUp
(
self
):
self
.
token
=
JiraOAuth1Token
(
os
.
environ
[
'JIRA_CLIENT_KEY'
],
os
.
environ
[
'JIRA_TEST_TOKEN'
],
os
.
environ
[
'JIRA_TEST_SECRET'
])
self
.
comment
=
JiraComment
(
self
.
token
,
10001
,
10001
)
def
test_number
(
self
):
self
.
assertEqual
(
self
.
comment
.
number
,
10001
)
def
test_type
(
self
):
self
.
assertEqual
(
self
.
comment
.
type
,
CommentType
.
ISSUE
)
def
test_body
(
self
):
self
.
assertEqual
(
self
.
comment
.
body
,
'Created 1 days ago
\r\n
Backlog to Selected for '
'Development 5 hours 12 minutes ago'
)
def
test_body_setter
(
self
):
self
.
comment
.
body
=
'test comment body has changed'
self
.
assertEqual
(
self
.
comment
.
body
,
'test comment body has changed'
)
def
test_author
(
self
):
with
self
.
assertRaises
(
NotImplementedError
):
self
.
assertEqual
(
self
.
comment
.
author
,
'yuki_is_bored'
)
def
test_time
(
self
):
self
.
assertEqual
(
self
.
comment
.
created
,
datetime
.
datetime
(
2018
,
3
,
16
,
8
,
4
,
27
,
968000
,
tzinfo
=
datetime
.
timezone
.
utc
))
self
.
assertEqual
(
self
.
comment
.
updated
,
datetime
.
datetime
(
2018
,
3
,
23
,
13
,
26
,
10
,
33000
,
tzinfo
=
datetime
.
timezone
.
utc
))
def
test_delete
(
self
):
with
requests_mock
.
Mocker
()
as
m
:
m
.
delete
(
requests_mock
.
ANY
,
text
=
'{}'
)
self
.
comment
.
delete
()
def
test_repository
(
self
):
with
self
.
assertRaises
(
NotImplementedError
):
self
.
assertEqual
(
self
.
comment
.
repository
.
full_name
,
'gitmate-test-user/test'
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment