This repository was archived by the owner on May 22, 2021. It is now read-only.
forked from sigmavirus24/github3.py
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomment.py
More file actions
121 lines (82 loc) · 3.11 KB
/
Copy pathcomment.py
File metadata and controls
121 lines (82 loc) · 3.11 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# -*- coding: utf-8 -*-
"""Module with class(es) representing issue comments."""
from .. import decorators
from .. import models
from .. import users
from .. import utils
class IssueComment(models.GitHubCore):
"""Representation of a comment left on an issue.
See also: http://developer.github.com/v3/issues/comments/
This object has the following attributes:
.. attribute:: author_association
The association of the author (:attr:`user`) with the repository
this issue belongs to.
.. attribute:: body
The markdown formatted original text written by the author.
.. attribute:: body_html
The HTML formatted comment body.
.. attribute:: body_text
The plain-text formatted comment body.
.. attribute:: created_at
A :class:`~datetime.datetime` object representing the date and time
when this comment was created.
.. attribute:: html_url
The URL to view this comment in a browser.
.. attribute:: id
The unique identifier for this comment.
.. attribute:: issue_url
The URL of the parent issue in the API.
.. attribute:: updated_at
A :class:`~datetime.datetime` object representing the date and time
when this comment was most recently updated.
.. attribute:: user
A :class:`~github4.users.ShortUser` representing the author of this
comment.
"""
def _update_attributes(self, comment):
self._api = comment["url"]
self.author_association = comment["author_association"]
self.body = comment["body"]
self.body_html = comment["body_html"]
self.body_text = comment["body_text"]
self.created_at = self._strptime(comment["created_at"])
self.html_url = comment["html_url"]
self.id = comment["id"]
self.issue_url = comment["issue_url"]
self.updated_at = self._strptime(comment["updated_at"])
self.user = users.ShortUser(comment["user"], self)
def _repr(self):
return "<IssueComment [{0}]>".format(self.user.login)
@decorators.requires_auth
def delete(self):
"""Delete this comment.
:returns: bool
"""
return self._boolean(self._delete(self._api), 204, 404)
@decorators.requires_auth
def edit(self, body):
"""Edit this comment.
:param str body: (required), new body of the comment, Markdown
formatted
:returns: bool
"""
if body:
json = self._json(self._patch(self._api, json={"body": body}), 200)
if json:
self._update_attributes(json)
return True
return False
def issue_comment_params(sort, direction, since):
"""Properly format parameters for issue comments.
.. warning::
This is not a public API designed for users of github4.py.
"""
params = {}
if sort in ("created", "updated"):
params["sort"] = sort
if direction in ("asc", "desc"):
params["direction"] = direction
since = utils.timestamp_parameter(since)
if since:
params["since"] = since
return params