Skip to content

Commit a340162

Browse files
rachmarilucascostiPeter Bengtsson
authored
reorganize repository apis (github#23728)
Co-authored-by: Lucas Costi <[email protected]> Co-authored-by: Peter Bengtsson <[email protected]>
1 parent d31d6a5 commit a340162

File tree

30 files changed

+2904
-2699
lines changed

30 files changed

+2904
-2699
lines changed

components/article/ArticlePage.tsx

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import { useState, useEffect } from 'react'
12
import { useRouter } from 'next/router'
3+
import dynamic from 'next/dynamic'
24
import cx from 'classnames'
35
import { ActionList, Heading } from '@primer/components'
46

@@ -17,6 +19,10 @@ import { ArticleGridLayout } from './ArticleGridLayout'
1719
import { PlatformPicker } from 'components/article/PlatformPicker'
1820
import { ToolPicker } from 'components/article/ToolPicker'
1921

22+
const ClientSideRedirectExceptions = dynamic(() => import('./ClientsideRedirectExceptions'), {
23+
ssr: false,
24+
})
25+
2026
// Mapping of a "normal" article to it's interactive counterpart
2127
const interactiveAlternatives: Record<string, { href: string }> = {
2228
'/actions/automating-builds-and-tests/building-and-testing-nodejs': {
@@ -79,8 +85,38 @@ export const ArticlePage = () => {
7985
)
8086
}
8187

88+
// We have some one-off redirects for rest api docs
89+
// currently those are limited to the repos page, but
90+
// that will grow soon as we restructure the rest api docs.
91+
// This is a workaround to updating the hardcoded links
92+
// directly in the REST API code in a separate repo, which
93+
// requires many file changes and teams to sign off.
94+
// While the organization is turbulent, we can do this.
95+
// Once it's more settled, we can refactor the rest api code
96+
// to leverage the OpenAPI urls rather than hardcoded urls.
97+
// The code below determines if we should bother loading this redirecting
98+
// component at all.
99+
// The reason this isn't done at the server-level is because there you
100+
// can't possibly access the URL hash. That's only known in client-side
101+
// code.
102+
const [loadClientsideRedirectExceptions, setLoadClientsideRedirectExceptions] = useState(false)
103+
useEffect(() => {
104+
const { hash, pathname } = window.location
105+
// Today, Jan 2022, it's known explicitly what the pathname.
106+
// In the future there might be more.
107+
// Hopefully, we can some day delete all of this and no longer
108+
// be dependent on the URL hash to do the redirect.
109+
if (hash && pathname.endsWith('/rest/reference/repos')) {
110+
setLoadClientsideRedirectExceptions(true)
111+
}
112+
}, [])
113+
82114
return (
83115
<DefaultLayout>
116+
{/* Doesn't matter *where* this is included because it will
117+
never render anything. It always just return null. */}
118+
{loadClientsideRedirectExceptions && <ClientSideRedirectExceptions />}
119+
84120
<div className="container-xl px-3 px-md-6 my-4">
85121
<ArticleGridLayout
86122
topper={<ArticleTitle>{title}</ArticleTitle>}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { useEffect } from 'react'
2+
import { useRouter } from 'next/router'
3+
4+
import overrides from '../../lib/redirects/static/rest-api-redirect-exceptions.json'
5+
const overrideRedirects: Record<string, string> = overrides
6+
7+
export default function ClientSideRedirectExceptions() {
8+
const router = useRouter()
9+
useEffect(() => {
10+
// We have some one-off redirects for rest api docs
11+
// currently those are limited to the repos page, but
12+
// that will grow soon as we restructure the rest api docs.
13+
// This is a workaround to updating the hardcoded links
14+
// directly in the REST API code in a separate repo, which
15+
// requires many file changes and teams to sign off.
16+
// While the organization is turbulent, we can do this.
17+
// Once it's more settled, we can refactor the rest api code
18+
// to leverage the OpenAPI urls rather than hardcoded urls.
19+
const { hash, pathname } = window.location
20+
21+
// The `hash` will start with a `#` but all the keys in
22+
// `overrideRedirects` do not. Hence, this slice.
23+
const combined = pathname + hash
24+
const overrideKey = combined
25+
.replace(`/${router.locale}`, '')
26+
.replace(`/${router.query.versionId || ''}`, '')
27+
const redirectToName = overrideRedirects[overrideKey]
28+
if (redirectToName) {
29+
const newPathname = combined.replace(overrideKey, redirectToName)
30+
router.replace(newPathname)
31+
}
32+
}, [])
33+
34+
return null
35+
}

components/page-header/RestRepoBanner.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const restDisplayPages = [
1111
'/rest/reference/pages',
1212
'/rest/reference/releases',
1313
'/rest/reference/repos',
14-
'/rest/reference/repository-metrics',
14+
'/rest/reference/metrics',
1515
'/rest/reference/webhooks',
1616
]
1717
const restRepoCategoryExceptionsTitles = {
@@ -21,7 +21,7 @@ const restRepoCategoryExceptionsTitles = {
2121
deployments: 'Deployments',
2222
pages: 'GitHub Pages',
2323
releases: 'Releases',
24-
'repository-metrics': 'Repository metrics',
24+
metrics: 'Metrics',
2525
webhooks: 'Webhooks',
2626
}
2727

content/rest/reference/branches.md

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,11 @@ topics:
1212
miniTocMaxHeadingLevel: 3
1313
---
1414

15-
## Branches
1615
{% for operation in currentRestOperations %}
17-
{% if operation.subcategory == 'branches' %}{% include rest_operation %}{% endif %}
16+
{% unless operation.subcategory %}{% include rest_operation %}{% endunless %}
1817
{% endfor %}
1918

20-
## Merging
21-
22-
The Repo Merging API supports merging branches in a repository. This accomplishes
23-
essentially the same thing as merging one branch into another in a local repository
24-
and then pushing to {% data variables.product.product_name %}. The benefit is that the merge is done on the server side and a local repository is not needed. This makes it more appropriate for automation and other tools where maintaining local repositories would be cumbersome and inefficient.
25-
26-
The authenticated user will be the author of any merges done through this endpoint.
27-
19+
## Protected branches
2820
{% for operation in currentRestOperations %}
29-
{% if operation.subcategory == 'merging' %}{% include rest_operation %}{% endif %}
21+
{% if operation.subcategory == 'branch-protection' %}{% include rest_operation %}{% endif %}
3022
{% endfor %}

content/rest/reference/collaborators.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@ topics:
1212
miniTocMaxHeadingLevel: 3
1313
---
1414

15-
## Collaborators
16-
1715
{% for operation in currentRestOperations %}
18-
{% if operation.subcategory == 'collaborators' %}{% include rest_operation %}{% endif %}
16+
{% unless operation.subcategory %}{% include rest_operation %}{% endunless %}
1917
{% endfor %}
2018

2119
## Invitations

content/rest/reference/commits.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Commits
3-
intro: 'The commits API allows you to retrieve information and commits, create commit comments, and create commit statuses.'
3+
intro: 'The commits API allows you to list, view, and compare commits in a repository. You can also interact with commit comments and commit statuses.'
44
allowTitleToDifferFromFilename: true
55
versions:
66
fpt: '*'
@@ -12,12 +12,8 @@ topics:
1212
miniTocMaxHeadingLevel: 3
1313
---
1414

15-
## Commits
16-
17-
The Repo Commits API supports listing, viewing, and comparing commits in a repository.
18-
1915
{% for operation in currentRestOperations %}
20-
{% if operation.subcategory == 'commits' %}{% include rest_operation %}{% endif %}
16+
{% unless operation.subcategory %}{% include rest_operation %}{% endunless %}
2117
{% endfor %}
2218

2319
## Commit comments

content/rest/reference/deployments.md

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,6 @@ topics:
1212
miniTocMaxHeadingLevel: 3
1313
---
1414

15-
## Deploy keys
16-
17-
{% data reusables.repositories.deploy-keys %}
18-
19-
Deploy keys can either be setup using the following API endpoints, or by using GitHub. To learn how to set deploy keys up in GitHub, see "[Managing deploy keys](/developers/overview/managing-deploy-keys)."
20-
21-
{% for operation in currentRestOperations %}
22-
{% if operation.subcategory == 'keys' %}{% include rest_operation %}{% endif %}
23-
{% endfor %}
24-
25-
## Deployments
26-
2715
Deployments are requests to deploy a specific ref (branch, SHA, tag). GitHub dispatches a [`deployment` event](/developers/webhooks-and-events/webhook-events-and-payloads#deployment) that external services can listen for and act on when new deployments are created. Deployments enable developers and organizations to build loosely coupled tooling around deployments, without having to worry about the implementation details of delivering different types of applications (e.g., web, native).
2816

2917
Deployment statuses allow external services to mark deployments with an `error`, `failure`, `pending`, `in_progress`, `queued`, or `success` state that systems listening to [`deployment_status` events](/developers/webhooks-and-events/webhook-events-and-payloads#deployment_status) can consume.
@@ -66,15 +54,30 @@ Keep in mind that GitHub is never actually accessing your servers. It's up to yo
6654

6755
Note that the `repo_deployment` [OAuth scope](/developers/apps/scopes-for-oauth-apps) grants targeted access to deployments and deployment statuses **without** granting access to repository code, while the {% ifversion not ghae %}`public_repo` and{% endif %}`repo` scopes grant permission to code as well.
6856

69-
7057
### Inactive deployments
7158

7259
When you set the state of a deployment to `success`, then all prior non-transient, non-production environment deployments in the same repository with the same environment name will become `inactive`. To avoid this, you can set `auto_inactive` to `false` when creating the deployment status.
7360

7461
You can communicate that a transient environment no longer exists by setting its `state` to `inactive`. Setting the `state` to `inactive` shows the deployment as `destroyed` in {% data variables.product.prodname_dotcom %} and removes access to it.
7562

7663
{% for operation in currentRestOperations %}
77-
{% if operation.subcategory == 'deployments' %}{% include rest_operation %}{% endif %}
64+
{% unless operation.subcategory %}{% include rest_operation %}{% endunless %}
65+
{% endfor %}
66+
67+
## Deployment statuses
68+
69+
{% for operation in currentRestOperations %}
70+
{% if operation.subcategory == 'statuses' %}{% include rest_operation %}{% endif %}
71+
{% endfor %}
72+
73+
## Deploy keys
74+
75+
{% data reusables.repositories.deploy-keys %}
76+
77+
Deploy keys can either be setup using the following API endpoints, or by using GitHub. To learn how to set deploy keys up in GitHub, see "[Managing deploy keys](/developers/overview/managing-deploy-keys)."
78+
79+
{% for operation in currentRestOperations %}
80+
{% if operation.subcategory == 'keys' %}{% include rest_operation %}{% endif %}
7881
{% endfor %}
7982

8083
{% ifversion fpt or ghes > 3.1 or ghae or ghec %}

content/rest/reference/index.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,32 @@ children:
1919
- /codes-of-conduct
2020
- /code-scanning
2121
- /codespaces
22-
- /commits
2322
- /collaborators
23+
- /commits
2424
- /dependabot
2525
- /deployments
2626
- /emojis
2727
- /enterprise-admin
2828
- /gists
2929
- /git
30-
- /pages
3130
- /gitignore
3231
- /interactions
3332
- /issues
3433
- /licenses
3534
- /markdown
3635
- /meta
36+
- /metrics
3737
- /migrations
3838
- /oauth-authorizations
3939
- /orgs
4040
- /packages
41+
- /pages
4142
- /projects
4243
- /pulls
4344
- /rate-limit
4445
- /reactions
4546
- /releases
4647
- /repos
47-
- /repository-metrics
4848
- /scim
4949
- /search
5050
- /secret-scanning

content/rest/reference/repository-metrics.md renamed to content/rest/reference/metrics.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
---
2-
title: Repository metrics
2+
title: Metrics
33
intro: 'The repository metrics API allows you to retrieve community profile, statistics, and traffic for your repository.'
44
allowTitleToDifferFromFilename: true
5+
redirect_from:
6+
- /rest/reference/repository-metrics
57
versions:
68
fpt: '*'
79
ghes: '*'
@@ -12,6 +14,10 @@ topics:
1214
miniTocMaxHeadingLevel: 3
1315
---
1416

17+
{% for operation in currentRestOperations %}
18+
{% unless operation.subcategory %}{% include rest_operation %}{% endunless %}
19+
{% endfor %}
20+
1521
{% ifversion fpt or ghec %}
1622
## Community
1723

content/rest/reference/pages.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@ In {% data variables.product.prodname_pages %} API endpoints that return GitHub
2828
- `path`: The repository directory from which the site publishes. Will be either `/` or `/docs`.
2929

3030
{% for operation in currentRestOperations %}
31-
{% if operation.subcategory == 'pages' %}{% include rest_operation %}{% endif %}
31+
{% unless operation.subcategory %}{% include rest_operation %}{% endunless %}
3232
{% endfor %}

content/rest/reference/releases.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,11 @@ miniTocMaxHeadingLevel: 3
1919
{% endnote %}
2020

2121
{% for operation in currentRestOperations %}
22-
{% if operation.subcategory == 'releases' %}{% include rest_operation %}{% endif %}
22+
{% unless operation.subcategory %}{% include rest_operation %}{% endunless %}
23+
{% endfor %}
24+
25+
## Release assets
26+
27+
{% for operation in currentRestOperations %}
28+
{% if operation.subcategory == 'assets' %}{% include rest_operation %}{% endif %}
2329
{% endfor %}

content/rest/reference/webhooks.md

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,36 @@ If you would like to set up a single webhook to receive events from all of your
1919
In addition to the REST API, {% data variables.product.prodname_dotcom %} can also serve as a [PubSubHubbub](#pubsubhubbub) hub for repositories.
2020

2121
{% for operation in currentRestOperations %}
22-
{% if operation.subcategory == 'webhooks' %}{% include rest_operation %}{% endif %}
22+
{% unless operation.subcategory %}{% include rest_operation %}{% endunless %}
2323
{% endfor %}
2424

25-
### Receiving Webhooks
25+
## Repository webhooks
26+
27+
{% for operation in currentRestOperations %}
28+
{% if operation.subcategory == 'repos' %}{% include rest_operation %}{% endif %}
29+
{% endfor %}
30+
31+
## Repository webhook configuration
32+
33+
{% for operation in currentRestOperations %}
34+
{% if operation.subcategory == 'repo-config' %}{% include rest_operation %}{% endif %}
35+
{% endfor %}
36+
37+
## Repository webhook deliveries
38+
39+
{% for operation in currentRestOperations %}
40+
{% if operation.subcategory == 'repo-deliveries' %}{% include rest_operation %}{% endif %}
41+
{% endfor %}
42+
43+
## Receiving Webhooks
2644

2745
In order for {% data variables.product.product_name %} to send webhook payloads, your server needs to be accessible from the Internet. We also highly suggest using SSL so that we can send encrypted payloads over HTTPS.
2846

29-
#### Webhook headers
47+
### Webhook headers
3048

3149
{% data variables.product.product_name %} will send along several HTTP headers to differentiate between event types and payload identifiers. See [webhook headers](/developers/webhooks-and-events/webhook-events-and-payloads#delivery-headers) for details.
3250

33-
### PubSubHubbub
51+
## PubSubHubbub
3452

3553
GitHub can also serve as a [PubSubHubbub](https://github.com/pubsubhubbub/PubSubHubbub) hub for all repositories. PSHB is a simple publish/subscribe protocol that lets servers register to receive updates when a topic is updated. The updates are sent with an HTTP POST request to a callback URL.
3654
Topic URLs for a GitHub repository's pushes are in this format:
@@ -39,21 +57,21 @@ Topic URLs for a GitHub repository's pushes are in this format:
3957

4058
The event can be any available webhook event. For more information, see "[Webhook events and payloads](/developers/webhooks-and-events/webhook-events-and-payloads)."
4159

42-
#### Response format
60+
### Response format
4361

4462
The default format is what [existing post-receive hooks should expect](/post-receive-hooks/): A JSON body sent as the `payload` parameter in a POST. You can also specify to receive the raw JSON body with either an `Accept` header, or a `.json` extension.
4563

4664
Accept: application/json
4765
https://github.com/{owner}/{repo}/events/push.json
4866

49-
#### Callback URLs
67+
### Callback URLs
5068

5169
Callback URLs can use the `http://` protocol.
5270

5371
# Send updates to postbin.org
5472
http://postbin.org/123
5573

56-
#### Subscribing
74+
### Subscribing
5775

5876
The GitHub PubSubHubbub endpoint is: `{% data variables.product.api_url_code %}/hub`. A successful request with curl looks like:
5977

@@ -67,7 +85,7 @@ curl -u "user" -i \
6785

6886
PubSubHubbub requests can be sent multiple times. If the hook already exists, it will be modified according to the request.
6987

70-
##### Parameters
88+
#### Parameters
7189

7290
Name | Type | Description
7391
-----|------|--------------
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
The webhook REST APIs enable you to manage repository, organization, and app webhooks.{% ifversion fpt or ghes > 3.2 or ghae or ghec %} You can use this API to list webhook deliveries for a webhook, or get and redeliver an individual delivery for a webhook, which can be integrated into an external app or service.{% endif %} You can also use the REST API to change the configuration of the webhook. For example, you can modify the payload URL, content type, SSL verification, and secret. For more information, see:
22

3-
- [Repository Webhooks REST API](/rest/reference/repos#webhooks)
3+
- [Repository Webhooks REST API](/rest/reference/webhooks#repository-webhooks)
44
- [Organization Webhooks REST API](/rest/reference/orgs#webhooks)
55
- [{% data variables.product.prodname_github_app %} Webhooks REST API](/rest/reference/apps#webhooks)

0 commit comments

Comments
 (0)