Integration with SourceHut's todo.sr.ht

I find myself often opening an issue in the Guix 'R Us issue tracker to package something new:

https://todo.sr.ht/~whereiseveryone/guixrus

My workflow is the following more or less:

I come across a cool package on GitHub or some other forge that would be a good candidate for packaging in the Guix 'R Us channel so I:

  1. Copy the link
  2. Open a new tab
  3. Navigate to guixrus — sourcehut todo
  4. Create a new issue
  5. Give the issue the title of the package
  6. Paste the package’s home page url in the issue description
  7. Tag the issue (e.g. cargo-build-system, python-build-system, etc.)
  8. Submit the issue

I’d like to be able to just press a keybind and do all of the above 8 steps in one go.

I guess I need to look into a GraphQL library for CL and then extend nyxt with it?

https://todo.sr.ht/graphql
https://man.sr.ht/graphql.md
https://man.sr.ht/todo.sr.ht/graphql.md

2 Likes

I guess I need to look into a GraphQL library for CL

Normally I like Shinmera’s work, but the README for cl-graphql makes it seem like it’s alpha quality. gql looks like your best bet these days, but I haven’t looked too extensively. It’s Scheme, but there’s a CHICKEN egg for the SourceHut API, although now that I think of it, I don’t think it’s GraphQL…

I don’t want to discourage you from working on this, but wouldn’t it be better to contribute to existing solutions for this on Emacs’s side? Forge’s sr.ht integration is partial but it’d be amazing to be able to interact with repos in the same way as with GitHub’s. I also find srht.el quite handy for basic operations, albeit being based on sr.ht’s REST API.

I may be out of context here, but for most of those actions (except maybe 7), you’d only need access to the page, and Nyxt can work with that. The simplest approach to the problem (and the one I’d likely take) would be to hack up a command to scrape the info from the original repo and then go to SourceHut to fill the issue page with the relevant info. Here’s a small snippet for how it might look:

(define-command open-guixrus-issue ()
  (let* ((buffer (current-buffer))
         (url (url buffer))
         ;; I don't have a SourceHut account, but there should be some
         ;; URL for new issue creation, right?
         (new-issue-url (quri:uri "https://todo.sr.ht/~whereiseveryone/guixrus/newissue")))
    (buffer-load
     new-issue-url
     :buffer buffer)
    ;; Bind an action to a hook. Arguments:
    ;; - Hook.
    ;; - Argument list for a hook, in this case the sole buffer.
    ;; - Body of the handler/callback.
    (hooks:on (buffer-loaded-hook buffer)
        (buffer)
      (when (quri:uri= (url buffer) new-issue-url)
        ;; `peval' is used to evaluate some Parenscript right away.
        (peval
         ;; `nyxt/ps:insert-at` inserts the text into an element. It's
         ;; quite rought around the edges, so you most probably want
         ;; something else, but here it is, for the sake of example.
         ;;
         ;; I tend to reproduce the initial text of the issue. See
         ;; https://github.com/aartaka/nyxt-config/blob/4550ec414bdbbd3412dcb4aca60252d836b8e5f7/commands.lisp#L3
         ;; and
         ;; https://github.com/aartaka/nyxt-config/blob/4550ec414bdbbd3412dcb4aca60252d836b8e5f7/commands.lisp#L53
         ;; for a use-case similar to yours.
         (nyxt/ps:insert-at (ps:@ document active-element)
                                  (render-url url)))))))

For sure, using something more structured, like GraphQL, is preferable to the fuzzy world of URLs and web-pages, but I find it quite tempting to work with this primordial soup anyway :slight_smile:

Also note that, if you’re on 3.*, there’s a part of the manual (nyxt:manual#headless-mode) dedicated to headless mode (unambiguously named “Headless Mode”), where you can find lots of useful things for web scraping and routine automation.

EDIT: Link to the manual.