emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: getting current repo info


From: Tassilo Horn
Subject: Re: getting current repo info
Date: Tue, 05 Oct 2021 10:07:45 +0200
User-agent: mu4e 1.7.0; emacs 29.0.50

Ag Ibragimov <agzam.ibragimov@gmail.com> writes:

> I'm trying to write a tiny helper for my own needs. It would have to
> fetch some data from GitHub. But I can't figure out how to get
> information about the current project.
>
> i.e., I have opened a file that belongs to a repository hosted on
> GitHub, for example, I cloned `github.com/emacs-mirror/emacs`, and I'm
> browsing through the files locally. To send some data to GitHub API, I
> need to know:
>
> - the owner            :: emacs-mirror
> - repo name            :: emacs
> - current branch-name  :: master
> - path to the file     :: let's say it's lisp/calculator.el
>
> What is the best way to get all that using magit, forge, or maybe some
> other package?

You can get owner and repo using the built-in vc.  bug-reference.el does
that, too, so have a look at `bug-reference-try-setup-from-vc'.
Essentially, it just gets the VCS URL and then the entries in
`bug-reference-setup-from-vc-alist' and
`bug-reference--setup-from-vc-alist' infer owner/project from that.  Of
course, the owner/project is just an convention of most forges.  And
also note that you could have setup many git remotes, so there could be
many "owners" and finding the "right" one is up to you.

As for the current branch, it seems there is no vc operation for that.
But `vc-git-dir-extra-headers' does it as part of its workings, so you
could copy this recipe if you want.

Bye,
Tassilo



reply via email to

[Prev in Thread] Current Thread [Next in Thread]