Skip to main content
L’API REST est maintenant versionnée. Pour plus d’informations, consultez « À propos des versions de l’API ».

Points de terminaison d’API REST pour les statistiques de dépôt

Utilisez l’API REST pour récupérer les données que GitHub Enterprise Cloud utilise pour visualiser différents types d’activités de dépôt.

À propos des statistiques de dépôt

Vous pouvez utiliser l’API REST pour récupérer les données que GitHub Enterprise Cloud utilise pour visualiser différents types d’activités de dépôt.

Bonnes pratiques pour la mise en cache

Le calcul des statistiques de dépôt est une opération coûteuse. Nous essayons donc de retourner les données mises en cache chaque fois que nous le pouvons. Si les données n’ont pas été mises en cache lorsque vous interrogez les statistiques d’un dépôt, vous recevrez une réponse 202. Un travail en arrière-plan sera également déclenché pour commencer la compilation de ces statistiques. Vous devez laisser au travail un court laps de temps, puis renvoyer la demande. Si le travail est terminé, cette demande recevra une réponse 200 dont le corps contiendra les statistiques.

Les statistiques de dépôt sont mises en cache par le SHA de la branche par défaut du dépôt. Si vous poussez les données vers la branche par défaut, cela réinitialisera le cache des statistiques.

Les statistiques excluent certains types de commits

Les statistiques exposées par l’API correspondent aux statistiques qui apparaissent dans différents graphes de dépôt.

En résumé :

  • Toutes les statistiques excluent les commits de fusion.
  • Les statistiques de contributeur excluent également les commits vides.

Get the weekly commit activity

Returns a weekly aggregate of the number of additions and deletions pushed to a repository.

Note: This endpoint can only be used for repositories with fewer than 10,000 commits. If the repository contains 10,000 or more commits, a 422 status code will be returned.

Jetons d’accès affinés pour « Get the weekly commit activity »

Ce point de terminaison fonctionne avec les types de jetons suivants:

Le jeton doit avoir l’ensemble d’autorisations suivant:

  • metadata:read

Ce point de terminaison peut être utilisé sans authentification ou sans les autorisations mentionnées ci-dessus si seules les ressources publiques sont demandées.

Paramètres pour « Get the weekly commit activity »

En-têtes
Nom, Type, Description
accept string

Setting to application/vnd.github+json is recommended.

Paramètres de chemin d’accès
Nom, Type, Description
owner string Obligatoire

The account owner of the repository. The name is not case sensitive.

repo string Obligatoire

The name of the repository without the .git extension. The name is not case sensitive.

Codes d’état de la réponse HTTP pour « Get the weekly commit activity »

Code d’étatDescription
200

Returns a weekly aggregate of the number of additions and deletions pushed to a repository.

202

Accepted

204

A header with no content is returned.

422

Repository contains more than 10,000 commits

Exemples de code pour « Get the weekly commit activity »

Exemple de requête

get/repos/{owner}/{repo}/stats/code_frequency
curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/repos/OWNER/REPO/stats/code_frequency

Returns a weekly aggregate of the number of additions and deletions pushed to a repository.

Status: 200
[ [ 1302998400, 1124, -435 ] ]

Get the last year of commit activity

Returns the last year of commit activity grouped by week. The days array is a group of commits per day, starting on Sunday.

Jetons d’accès affinés pour « Get the last year of commit activity »

Ce point de terminaison fonctionne avec les types de jetons suivants:

Le jeton doit avoir l’ensemble d’autorisations suivant:

  • metadata:read

Ce point de terminaison peut être utilisé sans authentification ou sans les autorisations mentionnées ci-dessus si seules les ressources publiques sont demandées.

Paramètres pour « Get the last year of commit activity »

En-têtes
Nom, Type, Description
accept string

Setting to application/vnd.github+json is recommended.

Paramètres de chemin d’accès
Nom, Type, Description
owner string Obligatoire

The account owner of the repository. The name is not case sensitive.

repo string Obligatoire

The name of the repository without the .git extension. The name is not case sensitive.

Codes d’état de la réponse HTTP pour « Get the last year of commit activity »

Code d’étatDescription
200

OK

202

Accepted

204

A header with no content is returned.

Exemples de code pour « Get the last year of commit activity »

Exemple de requête

get/repos/{owner}/{repo}/stats/commit_activity
curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/repos/OWNER/REPO/stats/commit_activity

Response

Status: 200
[ { "days": [ 0, 3, 26, 20, 39, 1, 0 ], "total": 89, "week": 1336280400 } ]

Get all contributor commit activity

Returns the total number of commits authored by the contributor. In addition, the response includes a Weekly Hash (weeks array) with the following information:

  • w - Start of the week, given as a Unix timestamp.
  • a - Number of additions
  • d - Number of deletions
  • c - Number of commits

Note: This endpoint will return 0 values for all addition and deletion counts in repositories with 10,000 or more commits.

Jetons d’accès affinés pour « Get all contributor commit activity »

Ce point de terminaison fonctionne avec les types de jetons suivants:

Le jeton doit avoir l’ensemble d’autorisations suivant:

  • metadata:read

Ce point de terminaison peut être utilisé sans authentification ou sans les autorisations mentionnées ci-dessus si seules les ressources publiques sont demandées.

Paramètres pour « Get all contributor commit activity »

En-têtes
Nom, Type, Description
accept string

Setting to application/vnd.github+json is recommended.

Paramètres de chemin d’accès
Nom, Type, Description
owner string Obligatoire

The account owner of the repository. The name is not case sensitive.

repo string Obligatoire

The name of the repository without the .git extension. The name is not case sensitive.

Codes d’état de la réponse HTTP pour « Get all contributor commit activity »

Code d’étatDescription
200

OK

202

Accepted

204

A header with no content is returned.

Exemples de code pour « Get all contributor commit activity »

Exemple de requête

get/repos/{owner}/{repo}/stats/contributors
curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/repos/OWNER/REPO/stats/contributors

Response

Status: 200
[ { "author": { "login": "octocat", "id": 1, "node_id": "MDQ6VXNlcjE=", "avatar_url": "https://github.com/images/error/octocat_happy.gif", "gravatar_id": "", "url": "https://api.github.com/users/octocat", "html_url": "https://github.com/octocat", "followers_url": "https://api.github.com/users/octocat/followers", "following_url": "https://api.github.com/users/octocat/following{/other_user}", "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}", "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/octocat/subscriptions", "organizations_url": "https://api.github.com/users/octocat/orgs", "repos_url": "https://api.github.com/users/octocat/repos", "events_url": "https://api.github.com/users/octocat/events{/privacy}", "received_events_url": "https://api.github.com/users/octocat/received_events", "type": "User", "site_admin": false }, "total": 135, "weeks": [ { "w": 1367712000, "a": 6898, "d": 77, "c": 10 } ] } ]

Get the weekly commit count

Returns the total commit counts for the owner and total commit counts in all. all is everyone combined, including the owner in the last 52 weeks. If you'd like to get the commit counts for non-owners, you can subtract owner from all.

The array order is oldest week (index 0) to most recent week.

The most recent week is seven days ago at UTC midnight to today at UTC midnight.

Jetons d’accès affinés pour « Get the weekly commit count »

Ce point de terminaison fonctionne avec les types de jetons suivants:

Le jeton doit avoir l’ensemble d’autorisations suivant:

  • metadata:read

Ce point de terminaison peut être utilisé sans authentification ou sans les autorisations mentionnées ci-dessus si seules les ressources publiques sont demandées.

Paramètres pour « Get the weekly commit count »

En-têtes
Nom, Type, Description
accept string

Setting to application/vnd.github+json is recommended.

Paramètres de chemin d’accès
Nom, Type, Description
owner string Obligatoire

The account owner of the repository. The name is not case sensitive.

repo string Obligatoire

The name of the repository without the .git extension. The name is not case sensitive.

Codes d’état de la réponse HTTP pour « Get the weekly commit count »

Code d’étatDescription
200

The array order is oldest week (index 0) to most recent week.

404

Resource not found

Exemples de code pour « Get the weekly commit count »

Exemple de requête

get/repos/{owner}/{repo}/stats/participation
curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/repos/OWNER/REPO/stats/participation

The array order is oldest week (index 0) to most recent week.

Status: 200
{ "all": [ 11, 21, 15, 2, 8, 1, 8, 23, 17, 21, 11, 10, 33, 91, 38, 34, 22, 23, 32, 3, 43, 87, 71, 18, 13, 5, 13, 16, 66, 27, 12, 45, 110, 117, 13, 8, 18, 9, 19, 26, 39, 12, 20, 31, 46, 91, 45, 10, 24, 9, 29, 7 ], "owner": [ 3, 2, 3, 0, 2, 0, 5, 14, 7, 9, 1, 5, 0, 48, 19, 2, 0, 1, 10, 2, 23, 40, 35, 8, 8, 2, 10, 6, 30, 0, 2, 9, 53, 104, 3, 3, 10, 4, 7, 11, 21, 4, 4, 22, 26, 63, 11, 2, 14, 1, 10, 3 ] }

Get the hourly commit count for each day

Each array contains the day number, hour number, and number of commits:

  • 0-6: Sunday - Saturday
  • 0-23: Hour of day
  • Number of commits

For example, [2, 14, 25] indicates that there were 25 total commits, during the 2:00pm hour on Tuesdays. All times are based on the time zone of individual commits.

Jetons d’accès affinés pour « Get the hourly commit count for each day »

Ce point de terminaison fonctionne avec les types de jetons suivants:

Le jeton doit avoir l’ensemble d’autorisations suivant:

  • metadata:read

Ce point de terminaison peut être utilisé sans authentification ou sans les autorisations mentionnées ci-dessus si seules les ressources publiques sont demandées.

Paramètres pour « Get the hourly commit count for each day »

En-têtes
Nom, Type, Description
accept string

Setting to application/vnd.github+json is recommended.

Paramètres de chemin d’accès
Nom, Type, Description
owner string Obligatoire

The account owner of the repository. The name is not case sensitive.

repo string Obligatoire

The name of the repository without the .git extension. The name is not case sensitive.

Codes d’état de la réponse HTTP pour « Get the hourly commit count for each day »

Code d’étatDescription
200

For example, [2, 14, 25] indicates that there were 25 total commits, during the 2:00pm hour on Tuesdays. All times are based on the time zone of individual commits.

204

A header with no content is returned.

Exemples de code pour « Get the hourly commit count for each day »

Exemple de requête

get/repos/{owner}/{repo}/stats/punch_card
curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/repos/OWNER/REPO/stats/punch_card

For example, [2, 14, 25] indicates that there were 25 total commits, during the 2:00pm hour on Tuesdays. All times are based on the time zone of individual commits.

Status: 200
[ [ 0, 0, 5 ], [ 0, 1, 43 ], [ 0, 2, 21 ] ]