Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce multiple GitHub token support #68

Merged
merged 2 commits into from
Jul 18, 2023
Merged

Introduce multiple GitHub token support #68

merged 2 commits into from
Jul 18, 2023

Conversation

lavoiesl
Copy link
Contributor

This enable multiple GitHub token support.

It starts by looking at whether there is a repo-specific token, then fall backs to more generic ones:

  • SMART_TODO_GITHUB_TOKEN__<ORG>__<REPO>
  • SMART_TODO_GITHUB_TOKEN__<ORG>
  • SMART_TODO_GITHUB_TOKEN (Default)

The <ORG> and <REPO> parts should be uppercased and use underscores.
For example, Shopify/my-repo would become SMART_TODO_GITHUB_TOKEN__SHOPIFY__MY_REPO=....

This is particularly helpful when needing to access multiple private orgs, each having their own private GitHub app

@lavoiesl lavoiesl requested review from rafaelfranca, Morriar and a team July 17, 2023 20:59
@lavoiesl lavoiesl merged commit 82fef66 into main Jul 18, 2023
@lavoiesl lavoiesl deleted the seb-multi-token branch July 18, 2023 13:04
@shopify-shipit shopify-shipit bot temporarily deployed to production July 18, 2023 13:08 Inactive
@etiennebarrie
Copy link
Member

The <ORG> and <REPO> parts should be uppercased and use underscores. For example, Shopify/my-repo would become SMART_TODO_GITHUB_TOKEN__SHOPIFY__MY_REPO=....

I wonder why we do that. There's no limitation for environment variables names beyond not containing \0 or =. I guess shells don't make it super easy to use environment variables with slashes, but with /usr/bin/env or using Kubernetes I don't think it would cause any issue? e.g.

env SMART_TODO_GITHUB_TOKEN__shopify/my_repo=42 ruby -e 'p ENV.select { /FOO/ =~ _1 }`
# {"FOO/BAR"=>"42"}

@lavoiesl
Copy link
Contributor Author

lavoiesl commented Jul 18, 2023

TIL.

But while that might be true, it feels brittle, unconventional, and a bit jarring. I went for this design to adhere to what I feel is an implicit standard.

For example, while this may work:

$ env SMART_TODO_GITHUB_TOKEN__shopify/my_repo=42 ruby -e 'p ENV.select { /repo/ =~ _1 }'
{"SMART_TODO_GITHUB_TOKEN__shopify/my_repo"=>"42"}

This doesn't:

$ SMART_TODO_GITHUB_TOKEN__shopify/my_repo=42 ruby -e 'p ENV.select { /repo/ =~ _1 }'
zsh: no such file or directory: SMART_TODO_GITHUB_TOKEN__shopify/my_repo=42

But this does:

$ SMART_TODO_GITHUB_TOKEN__SHOPIFY__MY_REPO=42 ruby -e 'p ENV.select { /MY_REPO/ =~ _1 }'
{"SMART_TODO_GITHUB_TOKEN__SHOPIFY__MY_REPO"=>"42"}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants