0
# Pull Request Workflows
1
2
Complete pull request operations including creation, review management, merging, file changes, review comments, and status checks.
3
4
## Capabilities
5
6
### Pull Request Access & Listing
7
8
Core operations for accessing and listing pull requests.
9
10
```python { .api }
11
class GitHub:
12
def pull_request(self, owner, repository, number):
13
"""
14
Get a specific pull request by number.
15
16
Args:
17
owner (str): Repository owner
18
repository (str): Repository name
19
number (int): Pull request number
20
21
Returns:
22
PullRequest: Pull request object or None if not found
23
"""
24
25
class Repository:
26
def pull_requests(self, state="open", head=None, base=None, sort="created", direction="desc"):
27
"""
28
List pull requests for this repository.
29
30
Args:
31
state (str): PR state ('open', 'closed', 'all')
32
head (str, optional): Head branch (user:branch format)
33
base (str, optional): Base branch
34
sort (str): Sort by ('created', 'updated', 'popularity', 'long-running')
35
direction (str): Sort direction ('asc', 'desc')
36
37
Returns:
38
iterator: Iterator of PullRequest objects
39
"""
40
41
def pull_request(self, number):
42
"""
43
Get a pull request by number.
44
45
Args:
46
number (int): Pull request number
47
48
Returns:
49
PullRequest: Pull request object or None
50
"""
51
```
52
53
### Pull Request Creation
54
55
Creating new pull requests.
56
57
```python { .api }
58
class Repository:
59
def create_pull(self, title, body="", head="", base="master", maintainer_can_modify=True, draft=False):
60
"""
61
Create a pull request.
62
63
Args:
64
title (str): Pull request title
65
body (str): Pull request description
66
head (str): Head branch (source branch)
67
base (str): Base branch (target branch)
68
maintainer_can_modify (bool): Allow maintainer edits
69
draft (bool): Create as draft PR
70
71
Returns:
72
PullRequest: Created pull request object
73
"""
74
75
def create_pull_from_issue(self, issue, head, base="master"):
76
"""
77
Create a pull request from an existing issue.
78
79
Args:
80
issue (int): Issue number
81
head (str): Head branch
82
base (str): Base branch
83
84
Returns:
85
PullRequest: Created pull request object
86
"""
87
```
88
89
### Pull Request Management
90
91
Editing and managing pull requests.
92
93
```python { .api }
94
class PullRequest:
95
def edit(self, title=None, body=None, state=None, base=None, maintainer_can_modify=None):
96
"""
97
Edit this pull request.
98
99
Args:
100
title (str, optional): New title
101
body (str, optional): New description
102
state (str, optional): New state ('open', 'closed')
103
base (str, optional): New base branch
104
maintainer_can_modify (bool, optional): Maintainer edit permission
105
106
Returns:
107
bool: True if successful
108
"""
109
110
def close(self):
111
"""
112
Close this pull request.
113
114
Returns:
115
bool: True if successful
116
"""
117
118
def reopen(self):
119
"""
120
Reopen this pull request.
121
122
Returns:
123
bool: True if successful
124
"""
125
```
126
127
### Pull Request Reviews
128
129
Managing pull request reviews and review comments.
130
131
```python { .api }
132
class PullRequest:
133
def reviews(self):
134
"""
135
List reviews for this pull request.
136
137
Returns:
138
iterator: Iterator of PullReview objects
139
"""
140
141
def create_review(self, body="", event="COMMENT", comments=None):
142
"""
143
Create a review for this pull request.
144
145
Args:
146
body (str): Review summary comment
147
event (str): Review event ('APPROVE', 'REQUEST_CHANGES', 'COMMENT')
148
comments (list, optional): List of review comments
149
150
Returns:
151
PullReview: Created review object
152
"""
153
154
def create_review_comment(self, body, commit_sha, path, position=None, line=None, side="RIGHT"):
155
"""
156
Create a review comment on a specific line.
157
158
Args:
159
body (str): Comment text
160
commit_sha (str): SHA of commit to comment on
161
path (str): File path
162
position (int, optional): Diff position (deprecated)
163
line (int, optional): Line number
164
side (str): Side of diff ('LEFT', 'RIGHT')
165
166
Returns:
167
ReviewComment: Created review comment object
168
"""
169
170
def review_comments(self, sort="created", direction="asc", since=None):
171
"""
172
List review comments for this pull request.
173
174
Args:
175
sort (str): Sort by ('created', 'updated')
176
direction (str): Sort direction ('asc', 'desc')
177
since (str, optional): ISO 8601 timestamp
178
179
Returns:
180
iterator: Iterator of ReviewComment objects
181
"""
182
```
183
184
### Pull Request Files & Diffs
185
186
Accessing changed files and diffs.
187
188
```python { .api }
189
class PullRequest:
190
def files(self):
191
"""
192
List files changed in this pull request.
193
194
Returns:
195
iterator: Iterator of PullFile objects
196
"""
197
198
def diff(self):
199
"""
200
Get the diff for this pull request.
201
202
Returns:
203
str: Unified diff content
204
"""
205
206
def patch(self):
207
"""
208
Get the patch for this pull request.
209
210
Returns:
211
str: Patch content
212
"""
213
```
214
215
### Pull Request Merging
216
217
Merging pull requests with different strategies.
218
219
```python { .api }
220
class PullRequest:
221
def merge(self, commit_message="", commit_title="", sha=None, merge_method="merge"):
222
"""
223
Merge this pull request.
224
225
Args:
226
commit_message (str): Merge commit message
227
commit_title (str): Merge commit title
228
sha (str, optional): SHA that PR head must match
229
merge_method (str): Merge method ('merge', 'squash', 'rebase')
230
231
Returns:
232
dict: Merge result with commit info
233
"""
234
235
def is_merged(self):
236
"""
237
Check if this pull request has been merged.
238
239
Returns:
240
bool: True if merged
241
"""
242
```
243
244
## Pull Request Model Classes
245
246
```python { .api }
247
class PullRequest:
248
"""Full pull request object with all data and methods."""
249
id: int
250
number: int
251
title: str
252
body: str
253
user: 'User'
254
state: str # 'open' or 'closed'
255
locked: bool
256
assignee: 'User'
257
assignees: list
258
requested_reviewers: list
259
milestone: 'Milestone'
260
head: dict # Branch info
261
base: dict # Target branch info
262
merged: bool
263
mergeable: bool
264
mergeable_state: str
265
merged_by: 'User'
266
comments: int
267
review_comments: int
268
commits: int
269
additions: int
270
deletions: int
271
changed_files: int
272
created_at: str
273
updated_at: str
274
closed_at: str
275
merged_at: str
276
merge_commit_sha: str
277
html_url: str
278
diff_url: str
279
patch_url: str
280
281
def edit(self, **kwargs): ...
282
def close(self): ...
283
def merge(self, **kwargs): ...
284
def create_review(self, body, event): ...
285
286
class ShortPullRequest:
287
"""Abbreviated pull request object."""
288
id: int
289
number: int
290
title: str
291
state: str
292
user: 'ShortUser'
293
294
class PullReview:
295
"""Pull request review."""
296
id: int
297
user: 'User'
298
body: str
299
state: str # 'PENDING', 'APPROVED', 'CHANGES_REQUESTED', 'COMMENTED'
300
html_url: str
301
pull_request_url: str
302
submitted_at: str
303
304
def edit(self, body): ...
305
def delete(self): ...
306
def dismiss(self, message): ...
307
308
class ReviewComment:
309
"""Pull request review comment."""
310
id: int
311
diff_hunk: str
312
path: str
313
position: int
314
original_position: int
315
commit_id: str
316
original_commit_id: str
317
user: 'User'
318
body: str
319
created_at: str
320
updated_at: str
321
html_url: str
322
pull_request_url: str
323
in_reply_to_id: int
324
325
def edit(self, body): ...
326
def delete(self): ...
327
def reply(self, body): ...
328
329
class PullFile:
330
"""File changed in pull request."""
331
sha: str
332
filename: str
333
status: str # 'added', 'removed', 'modified', 'renamed'
334
additions: int
335
deletions: int
336
changes: int
337
blob_url: str
338
raw_url: str
339
contents_url: str
340
patch: str
341
previous_filename: str
342
```