Skip to content

Commit 113553e

Browse files
committed
Merge pull request github#897 from github/update-1447279351
2 parents 2fee3b8 + be6d07f commit 113553e

File tree

3 files changed

+137
-0
lines changed

3 files changed

+137
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
kind: change
3+
title: Protected Branches API Preview Period
4+
created_at: 2015-11-11
5+
author_name: nakajima
6+
---
7+
8+
We're starting a preview period for the [protected branches](https://github.com/blog/2051-protected-branches-and-required-status-checks) API. Protecting a branch prevents force-pushes to it as well as deleting it. You can also specify required status checks that are required to merge code into the branch.
9+
10+
To protect a branch, make a `PATCH` request to the URL of the branch:
11+
12+
{:.terminal}
13+
curl "https://api.github.com/v3/repos/github/hubot/branches/master" \
14+
-XPATCH \
15+
-H 'Authorization: token TOKEN'
16+
-H "Accept: application/vnd.github.loki-preview" \
17+
-d "{\"protection\":{\"enabled\":true,\"required_status_checks\":{\"enforcement_level\":\"everyone\",\"contexts\":[\"required-status\"]}}}" \
18+
19+
#### How can I try it?
20+
21+
To access this functionality during the preview period, you’ll need to provide the following custom media type in the Accept header:
22+
23+
```
24+
application/vnd.github.loki-preview+json
25+
```
26+
27+
Take a look at [the docs here](/v3/repos/#enabling-and-disabling-branch-protection).
28+
29+
If you have any questions, please [get in touch](https://github.com/contact?form%5Bsubject%5D=Protected+Branches+API+Preview).

content/v3/repos.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,28 @@ List languages for the specified repository. The value on the right of a languag
255255

256256
GET /repos/:owner/:repo/branches
257257

258+
### Parameters
259+
260+
Name | Type | Description
261+
-----|------|-------------
262+
`protected`|`string` | Set to `1` or `true` to only return protected branches.
263+
264+
{{#tip}}
265+
266+
<a name="preview-period"></a>
267+
268+
The `protected` parameter is currently available for developers to preview.
269+
During the preview period, the API may change without advance notice.
270+
Please see the [blog post](/changes/2015-11-11-protected-branches-api) for full details.
271+
272+
To access the API during the preview period, you must provide a custom [media type](/v3/media) in the `Accept` header:
273+
274+
application/vnd.github.loki-preview+json
275+
276+
The `protection` key will only be present in branch payloads if this header is passed.
277+
278+
{{/tip}}
279+
258280
### Response
259281

260282
<%= headers 200, :pagination => default_pagination_rels %>
@@ -266,9 +288,81 @@ List languages for the specified repository. The value on the right of a languag
266288

267289
### Response
268290

291+
{{#tip}}
292+
293+
<a name="preview-period"></a>
294+
295+
The Protect Branch API is currently available for developers to preview.
296+
During the preview period, the API may change without advance notice.
297+
Please see the [blog post](/changes/2015-11-11-protected-branches-api) for full details.
298+
299+
To access the API during the preview period, you must provide a custom [media type](/v3/media) in the `Accept` header:
300+
301+
application/vnd.github.loki-preview+json
302+
303+
The `protection` key will only be present in branch payloads if this header is passed.
304+
305+
{{/tip}}
306+
269307
<%= headers 200 %>
270308
<%= json(:branch) %>
271309

310+
## Enabling and disabling branch protection
311+
312+
{{#tip}}
313+
314+
<a name="preview-period"></a>
315+
316+
The Protect Branch API is currently available for developers to preview.
317+
During the preview period, the API may change without advance notice.
318+
Please see the [blog post](/changes/2015-11-11-protected-branches-api) for full details.
319+
320+
To access the API during the preview period, you must provide a custom [media type](/v3/media) in the `Accept` header:
321+
322+
application/vnd.github.loki-preview+json
323+
324+
{{/tip}}
325+
326+
Protecting a branch requires admin access.
327+
328+
PATCH /repos/:owner/:repo/branches/:branch
329+
330+
### Input
331+
332+
You need to pass a `protection` object.
333+
334+
Name | Type | Description
335+
-----|------|-------------
336+
`enabled`|`boolean` | **Required**. Should this branch be protected or not
337+
`required_status_checks`|`object`| Configure required status checks here
338+
339+
The `required_status_checks` object must have the following keys:
340+
341+
Name | Type | Description
342+
-----|------|-------------
343+
`enforcement_level`|`string` | **Required**. Who required status checks apply to. Options are `off`, `non_admins` or `everyone`.
344+
`contexts`|`array` | **Required**. The list of required status checks to require in order to merge into this branch
345+
346+
The `enforcement_level` key can have the following values:
347+
348+
Name | Description
349+
------|------------
350+
`off` | Turn off required status checks for this branch.
351+
`non_admins` | Required status checks will be enforced for non-admins.
352+
`everyone` | Required status checks will be enforced for everyone (including admins)
353+
354+
#### Example
355+
356+
<%= json \
357+
"protection" => {
358+
"enabled" => true,
359+
"required_status_checks" => {
360+
"enforcement_level" => "everyone",
361+
"contexts" => ["continuous-integration/travis-ci"]
362+
}
363+
}
364+
%>
365+
272366
## Delete a Repository
273367

274368
Deleting a repository requires admin access. If OAuth is used, the

lib/resources.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,11 +357,25 @@ def fetch_content(key)
357357
"commit" => {
358358
"sha" => "6dcb09b5b57875f334f61aebed695e2e4193db5e",
359359
"url" => "https://api.github.com/repos/octocat/Hello-World/commits/c5b97d5ae6c19d5c5df71a34c7fbeeda2479ccbc"
360+
},
361+
"protection" => {
362+
"enabled" => false,
363+
"required_status_checks" => {
364+
"enforcement_level" => "off",
365+
"contexts" => []
366+
}
360367
}
361368
}
362369
]
363370

364371
BRANCH ||= {"name"=>"master",
372+
"protection" => {
373+
"enabled" => false,
374+
"required_status_checks" => {
375+
"enforcement_level" => "off",
376+
"contexts" => []
377+
}
378+
},
365379
"commit"=>
366380
{"sha"=>"7fd1a60b01f91b314f59955a4e4d4e80d8edf11d",
367381
"commit"=>

0 commit comments

Comments
 (0)