Introduction
Hello:)
Today, we will see how to get all the contributors in a GitHub repository.
We will be using JavaScript to fetch the data, from the GitHub api.
What is the GitHub Api?
The GitHub API is a way to interact with GitHub programmatically. You can use the GitHub API to create integrations, retrieve data, and automate your workflows. There are two types of GitHub APIs: a REST API and a GraphQL API. The REST API uses HTTP methods and paths to access GitHub resources, while the GraphQL API uses queries and mutations to manipulate GitHub data. You can use GitHub CLI, curl, the official Octokit libraries, or third-party libraries to make requests to either API. For more information, you can check out the following links:
- GitHub REST API documentation: This is the official documentation for the GitHub REST API. It provides reference information, guides, and examples for using the REST API.
- Getting started with the REST API: This is a guide that shows you how to use the GitHub REST API using GitHub CLI, JavaScript, or curl. It covers topics such as authentication, parameters, pagination, and scripting.
- About GitHub's APIs: This is an overview of the GitHub APIs, including the differences and similarities between the REST API and the GraphQL API. It also explains how to use GitHub CLI, curl, Octokit, and third-party libraries with the APIs.
How to fetch the contributors
All the GitHub APIs are stored at https://api.github.com/
.
So in order to fetch it you need to fetch the api from GitHub.
So, the api for GitHub contributors is https://api.github.com/repos/{Username}/{repo_name}/contributors
It will return the date in json format.
So, you can use fetch like this
const response = await fetch("https://api.github.com/repos/bashamega/webdevtools/contributors");
const data = await response.json();
then the data variable will be equal to all the contributers in json format like this:
[
{
"login": "Bashamega",
"id": 110662505,
"node_id": "U_kgDOBpiTaQ",
"avatar_url": "https://avatars.githubusercontent.com/u/110662505?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/Bashamega",
"html_url": "https://github.com/Bashamega",
"followers_url": "https://api.github.com/users/Bashamega/followers",
"following_url": "https://api.github.com/users/Bashamega/following{/other_user}",
"gists_url": "https://api.github.com/users/Bashamega/gists{/gist_id}",
"starred_url": "https://api.github.com/users/Bashamega/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/Bashamega/subscriptions",
"organizations_url": "https://api.github.com/users/Bashamega/orgs",
"repos_url": "https://api.github.com/users/Bashamega/repos",
"events_url": "https://api.github.com/users/Bashamega/events{/privacy}",
"received_events_url": "https://api.github.com/users/Bashamega/received_events",
"type": "User",
"site_admin": false,
"contributions": 42
}]
What are the meaning of these names?
Key | Definition |
---|---|
login | The username of the GitHub user. |
id | The unique ID associated with the GitHub user.. |
node_id | A unique identifier for the user in the GitHub GraphQL API. |
avatar_url | The URL of the user's avatar (profile picture). |
gravatar_id | The Gravatar ID of the user's avatar. Gravatar is a service for providing globally recognized avatars. In this case, it is an empty string. |
url | The URL to access the user's details via the GitHub API. |
html_url | The URL to view the user's profile on GitHub in a web browser. |
followers_url | The URL to access the list of followers for the user via the GitHub API. |
following_url | The URL to access the list of users the current user is following via the GitHub API." |
gists_url | The URL to access the list of gists (code snippets) associated with the user via the GitHub API." |
starred_url | The URL to access the list of repositories starred by the user via the GitHub API. |
subscriptions_url | The URL to access the list of repositories the user is subscribed to via the GitHub API. |
organizations_url | The URL to access the list of organizations the user is associated with via the GitHub API. |
repos_url | The URL to access the list of repositories owned by the user via the GitHub API. |
events_url | The URL to access the list of events associated with the user via the GitHub API |
received_events_url | The URL to access the list of events received by the user via the GitHub API." |
type | The type of user. In this case, it is "User" which indicates a regular GitHub user. |
site_admin | A boolean value that indicates whether the user is a site administrator or not. |
contributions | The number of contributions made by the user (e.g., commits, pull requests) to repositories on GitHub. |
Top comments (0)