gitfetch icon indicating copy to clipboard operation
gitfetch copied to clipboard

Sourcehut support

Open Zeviraty opened this issue 7 months ago • 5 comments

Adding sourcehut support should be possible, getting all commits of a user is impossible (atleast i think so) but getting all of the commits in their own repos is possible.

Graphql query:

query {
  me {
    repositories(filter: { count: 100 }) {
      results {
        log {
         cursor
         results {
          author {
          	email
            time
          }
         }
        }
      }
    }
  }
}

curl command:

echo '{
    "query": "query {\r\n  me {\r\n    repositories(filter: { count: 100 }) {\r\n      results {\r\n        log {\r\n         cursor\r\n         results {\r\n          author {\r\n          \temail\r\n            time\r\n          }\r\n         }\r\n        }\r\n      }\r\n    }\r\n  }\r\n}\r\n",
    "variables": {}
}' | curl --json @- \
    --oauth2-bearer "$bearer_token" \
    https://git.sr.ht/query

You should enumerate over result["data"]["me"]["repositories"]["results"] and in each repo enumerate over repo["log"]["results"] and if repo["log"] has a cursor that is not null, you should also go to the next page. and in each one of THOSE check if commit["author"]["email"] is equal to the user, and then you can take the time with commit["author"]["time"]

It is a lot, and a very nested dict. but it should be possible

Zeviraty avatar Apr 18 '26 17:04 Zeviraty

Thanks for raising the issue, will have a look on improving sourcehut integration.

Matars avatar Apr 19 '26 14:04 Matars

because at the moment it is broken: (after giving a correct token, or no token)

Could not get authenticated user: Token required for Sourcehut authentication Please ensure you have a valid token configured Error: Initialization failed

or with token

Could not get authenticated user: Could not get authenticated user: 403 Client Error: Forbidden for url: https://git.sr.ht/graphql Please ensure you have a valid token configured Error: Initialization failed

Zeviraty avatar Apr 20 '26 10:04 Zeviraty

The problem was that you were trying to call the graphql api at /graphql while it is at /query

Zeviraty avatar Apr 20 '26 10:04 Zeviraty

after changing that i run into: Error: Sourcehut API request failed: 422 Client Error: Unprocessable Entity for url: https://git.sr.ht/query

Zeviraty avatar Apr 20 '26 10:04 Zeviraty

oh uh forgot to say this but i created this quickly to try: https://git.sr.ht/~zevvi/sourcefetch You can take inspo from this

Zeviraty avatar May 11 '26 14:05 Zeviraty