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

feat(update): add support for shell GITHUB_TOKEN for GitHub API request #3271

Closed

Conversation

WybeBosch
Copy link

Pull Request: Add Support for GITHUB_TOKEN in Update & VCS

Commits:

  • 0e9d91e feat(vsc): add support for shell GITHUB_TOKEN for GitHub API request
  • ff0ef17 feat(update): add support for shell GITHUB_TOKEN for GitHub API request

Description

This pull request adds the ability to use the GITHUB_TOKEN environment variable for authenticated requests to the GitHub API. While this is not a complete solution to all github api requests e.g. its not for requests being made from the spotify interface via javascript, this does add an option to lessen the rate limit for purely terminal requests.

Main changes

  1. update.go

    • Replaced:
      resp2, err := http.Get(assetURL)
      if err != nil {
        utils.Fatal(err)
      }
    • With:
      req, err := http.NewRequest("GET", assetURL, nil)
      if err != nil {
        utils.Fatal(err)
      }
      
      githubToken := os.Getenv("GITHUB_TOKEN")
      if githubToken != "" {
        utils.PrintInfo("Using GITHUB_TOKEN as your PersonalAccesToken for GitHub request")
        req.Header.Set("Authorization", "token "+githubToken)
      }
      resp2, err := http.DefaultClient.Do(req)
      if err != nil {
        utils.Fatal(err)
      }
      defer resp2.Body.Close()
  2. vcs.go

    • Replaced:
      res, err := http.Get("https://api.github.com/repos/spicetify/cli/releases/latest")
      if err != nil {
        return "", err
      }
    • With:
      req, err := http.NewRequest("GET", "https://api.github.com/repos/spicetify/cli/releases/latest", nil)
      if err != nil {
        return "", err
      }
      
      githubToken := os.Getenv("GITHUB_TOKEN")
      if githubToken != "" {
        req.Header.Set("Authorization", "token "+githubToken)
      }
      res, err := http.DefaultClient.Do(req)
      if err != nil {
        return "", err
      }
      defer res.Body.Close()
    • Added import "os" to access os.Getenv.

Reasoning

  • Authentication: Providing the GITHUB_TOKEN in HTTP headers allows authorized requests, which can bypass anonymous github rate limits.
  • Backwards Compatibility: If no GITHUB_TOKEN is found, the request stays unauthenticated as before.

How to Test

  1. Temporarly set the GITHUB_TOKEN environment variable:
    export GITHUB_TOKEN=<your_token_here>

@WybeBosch
Copy link
Author

WybeBosch commented Jan 17, 2025

Hmm the build checks seem to fail here

Run gofmt -s -l .
src/utils/vcs.go
Error: Process completed with exit code 1.

And if i run the command locally

gofmt -s -l

it doesnt seem to do much and just hang.

I didnt really modify that much code, and kept the same spacing / tabbing.
Not sure what to modify without further debugging the linting

The command

go build -ldflags "-X main.version=$(git describe --tags)" -o ./spicetify

Seems to locally work just fine to build the application.

@rxri
Copy link
Member

rxri commented Jan 17, 2025

Sorry, but your pull request has no sense at all. It only modifies the requests in two places (to fetch the latest/specific version), uses the user's GITHUB_TOKEN that someone may hold for different thing and this pull request is changing the way of how the program works which not everyone would appreciate - meaning, you're selfishly getting the token without asking for it and doesn't really address the marketplace issue which you all talk about. Like I have said, this is not something I'm going to approve or even have a conversation about anymore because per my last comment, you're free to change it locally and build it locally and use it however you like since it's open-source project, but this is not going to land in the cli or just set the check_spicetify_upgrade config option to 0.

@rxri rxri closed this Jan 17, 2025
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.

2 participants