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
2828 # self.GITHUB_TOKEN = GITHUB_TOKEN
2929 self .update_keys = [
@@ -52,17 +52,18 @@ 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.
55+ # This is already in the github api module
56+ # def get_token(self) -> str:
57+ # """Fetches the GitHub API key from the users environment. If running
58+ # local from an .env file.
5859
59- Returns
60- -------
61- str
62- The provided API key in the .env file.
63- """
64- load_dotenv ()
65- return os .environ ["GITHUB_TOKEN" ]
60+ # Returns
61+ # -------
62+ # str
63+ # The provided API key in the .env file.
64+ # """
65+ # load_dotenv()
66+ # return os.environ["GITHUB_TOKEN"]
6667
6768 def check_contrib_type (self , json_file : str ):
6869 """
@@ -94,6 +95,7 @@ def check_contrib_type(self, json_file: str):
9495 contrib_type = "community"
9596 return contrib_type
9697
98+ # Possibly github it is a get request but it says json path
9799 def load_json (self , json_path : str ) -> dict :
98100 """
99101 Helper function that deserializes a json file to a dict.
@@ -153,19 +155,19 @@ def combine_json_data(self) -> dict:
153155 print ("Oops - can't process" , json_file , e )
154156 return combined_data
155157
156- def get_user_info (
157- self , username : str , aname : Optional [str ] = None
158- ) -> dict :
158+ def return_user_info (
159+ self , gh_handle : str , name : Optional [str ] = None
160+ ) -> dict [ str , Any ] :
159161 """
160162 Get a single user's information from their GitHub username using the
161163 GitHub API
162164 # https://docs.github.com/en/rest/users/users?apiVersion=2022-11-28#get-the-authenticated-user
163165
164166 Parameters
165167 ----------
166- username : string
168+ gh_handle : string
167169 Github username to retrieve data for
168- aname : str default=None
170+ name : str default=None
169171 A user's name from the contributors.yml file.
170172 https://docs.github.com/en/rest/users/users?apiVersion=2022-11-28#get-a-user
171173
@@ -174,12 +176,13 @@ def get_user_info(
174176 Dict with updated user data grabbed from the GH API
175177 """
176178
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 ()
179+ response_json = self .github_api .get_user_info (gh_handle , name )
180+ # url = f"https://api.github.com/users/{username}"
181+ # headers = {"Authorization": f"Bearer {self.get_token()}"}
182+ # response = requests.get(url, headers=headers)
183+ # # TODO: add check here for if credentials are bad
184+ # # if message = Bad credentials
185+ # response_json = response.json()
183186
184187 # TODO: make an attribute and call it here?
185188 update_keys = {
0 commit comments