repository-traffic-action icon indicating copy to clipboard operation
repository-traffic-action copied to clipboard

Action will fail in forks

Open thias15 opened this issue 3 years ago • 5 comments

Thanks for this very handy action. The problem I encountered is that the action will fail for anyone forking the repo since it relies on a PAT. Any ideas for a workaround?

thias15 avatar Nov 12 '21 12:11 thias15

Hi @thias15! Should a forked repositories views and clones count towards the upstream repository? Do you know what GitHub does for this scenario?

I think I would expect a forked repos stats to be separate from the upstream repo, given that forked repo can become it's own separate thing.

Either way I don't think there is anything that can be done, apart from the person who forked creating a PAT and using it to log metrics for the fork.

sangonzal avatar Nov 12 '21 15:11 sangonzal

It would be nice to have the repo name as an input rather than using GITHUB_REPOSITORY

thias15 avatar Dec 22 '21 18:12 thias15

Sorry, hadn't seen your latest comment. I think it would be reasonable to let the user override GITHUB_REPOSITORY with their own value by setting an env variable. By the way have you tried overriding GITHUB_REPOSITORY by setting it on the yaml file? Something along the lines of:

    - name: GitHub traffic 
      uses: sangonzal/[email protected]
      env:
        TRAFFIC_ACTION_TOKEN: ${{ secrets.TRAFFIC_ACTION_TOKEN }}
         GITHUB_REPOSITORY: name_you_want_to_use

I don't have time to make the changes and test right now, but if you'd like to make the change I would merge the pull request in and release a new version.

sangonzal avatar Feb 11 '22 17:02 sangonzal

Hi @sangonzal 👋🏽 I've tried your suggestion about using the GITHUB_REPOSITORY env but couldn't get it to work.

I'm running your action from the innovyze/Traffic-Data repository on traffic from the innovyze/Open-Source-Support repository.

See below: image

It seems that the environment variable has been recognised, but the action is still being applied to traffic in the innovyze/Traffic-Data repository.

Do you know what I'm getting wrong?

dfmore avatar Mar 18 '22 17:03 dfmore

Hi @dfmore, I haven't actually tried to do this before, so I don't know if overriding GITHUB_REPOSITORY actually works. From your screenshot, it seems that Github might not allow you to override env variables that they set.

Another way of going about this is to define another env variable, something like REPOSITORY_NAME, and check in main.py if it's set. If REPOSITORY_NAME is set, then use it, if not then fallback to GITHUB_REPOSITORY.

I don't have time to make the changes right now and test, but happy to merge in a PR with these changes. Next time I do have time to work on the project I'll see if I can get this in.

sangonzal avatar Mar 18 '22 18:03 sangonzal