Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4fefea0

Browse files
Merge pull request avinashkranjan#127 from HyperTHD/issue-126
Created script.py as per avinashkranjan#126
2 parents 18e69d5 + d34c0eb commit 4fefea0

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Github Size-Contributor-List
2+
3+
## What this script accomplishes
4+
5+
- Makes an API call to the, "Github API" in order to retrieve the information needed. It retrieves the size of the repository and the number of contributors the repo has
6+
- Information is saved to a text file called, "output.txt"
7+
8+
## How ro run script
9+
10+
### 1. Download script and install requests
11+
```
12+
pip install requests
13+
```
14+
15+
### 2. Run script.py and specify the name of the github user and name of the repository as follows
16+
```
17+
python script.py -o NAMEOFGITHUBUSER -n NAMEOFGITHUBREPO
18+
```
19+
20+
Note that the repo must be owned by the user, otherwise, it will fail.
21+
22+
23+
### 3. Output of the script will be written to a text file called, "output.txt". If the script has incorrect values, it won't run. If the script could not gather data, nothing will be written.
24+
25+
26+
## Example Output
27+
![OutputText](https://i.imgur.com/Ckttce3.png)
28+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import requests
2+
import argparse
3+
4+
def main(args):
5+
GITHUB_URL = f" https://api.github.com/repos/{args.o}/{args.n}"
6+
res = requests.get(GITHUB_URL).json()
7+
response_collaborators = requests.get(f"{GITHUB_URL}/contributors").json()
8+
9+
response_text = f"Size of repository is {res.get('size')}"
10+
11+
list_of_contributors = []
12+
13+
for x in response_collaborators:
14+
list_of_contributors.append(x.get("login"))
15+
16+
with open("output.txt", "w") as text:
17+
text.write(response_text + "\n" + "List of contributors is as follows: " + str(list_of_contributors))
18+
19+
20+
parser = argparse.ArgumentParser("This script displays the size and list of contributors for a specific repo")
21+
parser.add_argument("-o", help="The name of the user", type=str, required=True)
22+
parser.add_argument("-n", help="The name of the repo", type=str, required=True)
23+
24+
args = parser.parse_args()
25+
26+
main(args)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /