11import json
2- import os
32
43import requests
54from dataclasses import dataclass
6- from dotenv import load_dotenv
7- from typing import List , Optional , Tuple
5+ from typing import Any , List , Optional , Tuple
6+
7+ from .github_api import GitHubAPI
88
99
1010@dataclass
1111class ProcessContributors :
1212 """A class that contains some basic methods to support populating and
1313 updating contributor data."""
1414
15- def __init__ (self , json_files : List ) -> None :
15+ def __init__ (self , github_api : GitHubAPI , json_files : List ) -> None :
1616 """
1717 Parameters
1818 ----------
19-
19+ github_api : str
20+ Instantiated instance of a GitHubAPI object
2021 json_files : list
2122 A list of string objects each of which represents a URL to a JSON
2223 file to be parsed
23- GITHUB_TOKEN : str
24- A string containing your API token needed to access the github API
2524 """
2625
26+ self .github_api = github_api
2727 self .json_files = json_files
28- # self.GITHUB_TOKEN = GITHUB_TOKEN
28+
2929 self .update_keys = [
3030 "twitter" ,
3131 "website" ,
@@ -52,18 +52,6 @@ def __init__(self, json_files: List) -> None:
5252 ],
5353 }
5454
55- def get_token (self ) -> str :
56- """Fetches the GitHub API key from the users environment. If running
57- local from an .env file.
58-
59- Returns
60- -------
61- str
62- The provided API key in the .env file.
63- """
64- load_dotenv ()
65- return os .environ ["GITHUB_TOKEN" ]
66-
6755 def check_contrib_type (self , json_file : str ):
6856 """
6957 Determine the type of contribution the person
@@ -94,6 +82,7 @@ def check_contrib_type(self, json_file: str):
9482 contrib_type = "community"
9583 return contrib_type
9684
85+ # Possibly github it is a get request but it says json path
9786 def load_json (self , json_path : str ) -> dict :
9887 """
9988 Helper function that deserializes a json file to a dict.
@@ -153,19 +142,19 @@ def combine_json_data(self) -> dict:
153142 print ("Oops - can't process" , json_file , e )
154143 return combined_data
155144
156- def get_user_info (
157- self , username : str , aname : Optional [str ] = None
158- ) -> dict :
145+ def return_user_info (
146+ self , gh_handle : str , name : Optional [str ] = None
147+ ) -> dict [ str , Any ] :
159148 """
160149 Get a single user's information from their GitHub username using the
161150 GitHub API
162151 # https://docs.github.com/en/rest/users/users?apiVersion=2022-11-28#get-the-authenticated-user
163152
164153 Parameters
165154 ----------
166- username : string
155+ gh_handle : string
167156 Github username to retrieve data for
168- aname : str default=None
157+ name : str default=None
169158 A user's name from the contributors.yml file.
170159 https://docs.github.com/en/rest/users/users?apiVersion=2022-11-28#get-a-user
171160
@@ -174,14 +163,8 @@ def get_user_info(
174163 Dict with updated user data grabbed from the GH API
175164 """
176165
177- url = f"https://api.github.com/users/{ username } "
178- headers = {"Authorization" : f"Bearer { self .get_token ()} " }
179- response = requests .get (url , headers = headers )
180- # TODO: add check here for if credentials are bad
181- # if message = Bad credentials
182- response_json = response .json ()
166+ response_json = self .github_api .get_user_info (gh_handle , name )
183167
184- # TODO: make an attribute and call it here?
185168 update_keys = {
186169 "name" : "name" ,
187170 "location" : "location" ,
0 commit comments