Skip to main content
Frecuentemente publicamos actualizaciones de nuestra documentación. Es posible que la traducción de esta página esté en curso. Para conocer la información más actual, visita la documentación en inglés. Si existe un problema con las traducciones en esta página, por favor infórmanos.

Esta versión de GitHub Enterprise se discontinuó el 2022-06-03. No se realizarán lanzamientos de patch, ni siquiera para problemas de seguridad críticos. Para obtener un mejor desempeño, más seguridad y nuevas características, actualiza a la última versión de GitHub Enterprise. Para obtener ayuda con la actualización, contacta al soporte de GitHub Enterprise.

We've recently moved some of the REST API documentation. If you can't find what you're looking for, you might try the new Branches, Collaborators, Commits, Deploy Keys, Deployments, GitHub Pages, Releases, Metrics, Webhooks REST API pages.

Repository statistics

The Repository statistics API allows you to fetch the data that GitHub Enterprise Server uses for visualizing different types of repository activity.

About the Repository statistics API

La API de estadísticas de repositorio te permite recuperar los datos que GitHub Enterprise Server utiliza para visualizar tipos diferentes de actividad de repositorio.

Unas palabras sobre el almacenamiento en caché

El calcular las estadísitcas del repositorio es una operación costosa, así que intentamos devolver los datos almacenados en caché cuando nos es posible. Si los datos no se han almacenado en caché cuando consultas la estadística de un repositorio, recibirás una respuesta 202; también se dispara un job en segundo plano para comenzar a compilar estas estadísticas. Permite que el job se complete, y luego emite la solicitud nuevamente. Si el job ya terminó, esa solicitud recibirá una respuesta 200 con la estadística en el cuerpo de la respuesta.

El SHA de la rama predeterminada del repositorio guarda en caché las estadísticas del repositorio; el subir información a la rama predeterminada restablece el caché de de las estadísticas.

Las estadísticas excluyen algunos tipos de confirmaciones

Las estadísticas que expone la API empatan con aquellas que muestran diversas gráficas del repositorio.

Para resumir:

  • Todas las estadísticas excluyen las confirmaciones de fusión.
  • Las estadísticas del colaborador también excluyen a las confirmaciones vacías.

Get the weekly commit activity

Funciona con GitHub Apps

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

Parámetros

Encabezados
Nombre, Tipo, Descripción
acceptstring

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

Parámetros de ruta
Nombre, Tipo, Descripción
ownerstringRequerido

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

repostringRequerido

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

Códigos de estado de respuesta HTTP

Código de estadoDescripción
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.

Ejemplos de código

get/repos/{owner}/{repo}/stats/code_frequency
curl \ -H "Accept: application/vnd.github.v3+json" \ -H "Authorization: token <TOKEN>" \ http(s)://HOSTNAME/api/v3/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

Funciona con GitHub Apps

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

Parámetros

Encabezados
Nombre, Tipo, Descripción
acceptstring

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

Parámetros de ruta
Nombre, Tipo, Descripción
ownerstringRequerido

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

repostringRequerido

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

Códigos de estado de respuesta HTTP

Código de estadoDescripción
200

OK

202

Accepted

204

A header with no content is returned.

Ejemplos de código

get/repos/{owner}/{repo}/stats/commit_activity
curl \ -H "Accept: application/vnd.github.v3+json" \ -H "Authorization: token <TOKEN>" \ http(s)://HOSTNAME/api/v3/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

Funciona con GitHub Apps

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

Parámetros

Encabezados
Nombre, Tipo, Descripción
acceptstring

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

Parámetros de ruta
Nombre, Tipo, Descripción
ownerstringRequerido

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

repostringRequerido

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

Códigos de estado de respuesta HTTP

Código de estadoDescripción
200
  • w - Start of the week, given as a Unix timestamp.
  • a - Number of additions
  • d - Number of deletions
  • c - Number of commits
202

Accepted

204

A header with no content is returned.

Ejemplos de código

get/repos/{owner}/{repo}/stats/contributors
curl \ -H "Accept: application/vnd.github.v3+json" \ -H "Authorization: token <TOKEN>" \ http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/stats/contributors
  • w - Start of the week, given as a Unix timestamp.
  • a - Number of additions
  • d - Number of deletions
  • c - Number of commits
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

Funciona con GitHub Apps

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.

Parámetros

Encabezados
Nombre, Tipo, Descripción
acceptstring

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

Parámetros de ruta
Nombre, Tipo, Descripción
ownerstringRequerido

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

repostringRequerido

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

Códigos de estado de respuesta HTTP

Código de estadoDescripción
200

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

404

Resource not found

Ejemplos de código

get/repos/{owner}/{repo}/stats/participation
curl \ -H "Accept: application/vnd.github.v3+json" \ -H "Authorization: token <TOKEN>" \ http(s)://HOSTNAME/api/v3/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

Funciona con GitHub Apps

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.

Parámetros

Encabezados
Nombre, Tipo, Descripción
acceptstring

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

Parámetros de ruta
Nombre, Tipo, Descripción
ownerstringRequerido

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

repostringRequerido

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

Códigos de estado de respuesta HTTP

Código de estadoDescripción
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.

Ejemplos de código

get/repos/{owner}/{repo}/stats/punch_card
curl \ -H "Accept: application/vnd.github.v3+json" \ -H "Authorization: token <TOKEN>" \ http(s)://HOSTNAME/api/v3/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 ] ]