georgetown-cset / funder-finder

Retrieve GitHub repo funding information
Apache License 2.0
7 stars 2 forks source link

[BUG] Error When Using get_funders.py #42

Closed jspeed-meyers closed 1 year ago

jspeed-meyers commented 1 year ago

When I run:

python3 funderfinder/get_funders.py repo_name=georgetown-cset/funder-finder

I get:

Traceback (most recent call last):
  File "/Users/johnspeedmeyers/Desktop/repos/public/funder-finder/funderfinder/get_funders.py", line 39, in <module>
    print(get_project_funders(args.repo_name))
  File "/Users/johnspeedmeyers/Desktop/repos/public/funder-finder/funderfinder/get_funders.py", line 20, in get_project_funders
    funding = finder.run(repo_name)
  File "/Users/johnspeedmeyers/Desktop/repos/public/funder-finder/funderfinder/sources/github_sponsors.py", line 174, in run
    top_contribs = self.get_gh_top_contributors_json(gh_project_slug)
  File "/Users/johnspeedmeyers/Desktop/repos/public/funder-finder/funderfinder/sources/github_sponsors.py", line 93, in get_gh_top_contributors_json
    for contributor in contributors:
UnboundLocalError: local variable 'contributors' referenced before assignment

Am I doing something wrong? Is there really a bug? pytest passes when I run it. hmmm...

jspeed-meyers commented 1 year ago

It seems that using:

python3 funderfinder/get_funders.py repo_name=https://github.com/georgetown-cset/funder-finder

gets me past that bug, but then I have a new one.

New bug:

Traceback (most recent call last):
  File "/Users/johnspeedmeyers/Desktop/repos/public/funder-finder/funderfinder/get_funders.py", line 39, in <module>
    print(get_project_funders(args.repo_name))
  File "/Users/johnspeedmeyers/Desktop/repos/public/funder-finder/funderfinder/get_funders.py", line 20, in get_project_funders
    funding = finder.run(repo_name)
  File "/Users/johnspeedmeyers/Desktop/repos/public/funder-finder/funderfinder/sources/github_sponsors.py", line 178, in run
    num_sponsors = self.parse_gh_user_gh_sponsors_json(sponsors_json)
  File "/Users/johnspeedmeyers/Desktop/repos/public/funder-finder/funderfinder/sources/github_sponsors.py", line 144, in parse_gh_user_gh_sponsors_json
    gh_user_gh_sponsors_json["data"]["user"]["sponsors"]["edges"]
KeyError: 'data'
jspeed-meyers commented 1 year ago

Ah, it looks like it's related to the scope of the token. Trying a fix now.

Two initial thoughts:

jspeed-meyers commented 1 year ago

The scopes must include public_repo, read:org and user:email

jspeed-meyers commented 1 year ago

And now new error:

Traceback (most recent call last):
  File "/Users/johnspeedmeyers/Desktop/repos/public/funder-finder/funderfinder/get_funders.py", line 39, in <module>
    print(get_project_funders(args.repo_name))
  File "/Users/johnspeedmeyers/Desktop/repos/public/funder-finder/funderfinder/get_funders.py", line 19, in get_project_funders
    finder = finder_class()
  File "/Users/johnspeedmeyers/Desktop/repos/public/funder-finder/funderfinder/sources/opencollective.py", line 20, in __init__
    assert os.environ.get(
AssertionError: Please `export OPENCOLLECTIVE_API_KEY=<your opencollective api key>

So the documentation should also add information on adding an Open Collective API key. In fact, I don't know how to do that. I need to look into that.

jspeed-meyers commented 1 year ago

The documentation here works: https://blog.opencollective.com/open-collective-graphql-api-preview/

Okay, so I'll add this to the README too!

jspeed-meyers commented 1 year ago

PR #34 now includes Open Collective API information.

@jmelot:

The documentation should be specific on what the input to the repo_name argument should be. The documentation should be specific on the scopes needs for the GitHub token.

Do I have the scopes (public_repo, read:org and user:email) for the GitHub token correct? And should the repo_name flag actually use the full GitHub URL and not just the org and repo name?

Once I get your input on this, I can further revise PR #34 (or we can merge #34 as is and I can work on another PR).

jmelot commented 1 year ago

So three things:

1.) The repo_name arg is a positional argument. If you pass in repo_name=foo/bar, the entire string repo_name=foo/bar is passed as the github url, which leads to an unmatched repo. I updated the readme to reflect this

2.) The github_sponsors finder doesn't handle repos that don't exist, it would seem, I'll submit a PR to fix this

3.) Yeah, a token with scopes admin:org, read:user, repo, user:email, workflow does work! If you're willing to update the README to reflect this I'm all for it

jspeed-meyers commented 1 year ago

Sweet. I'll work on a new PR on Friday.