emacs-devel
[Top][All Lists]
Advanced

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

Re: getting current repo info


From: Omar Polo
Subject: Re: getting current repo info
Date: Tue, 05 Oct 2021 09:30:10 +0200
User-agent: mu4e 1.6.6; emacs 28.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?

vc.el provides a 'repository-url that some backends implement.  By
parsing the repository-url I guess you can extract the owner and repo
name.  The repository-url can be obtained with something along the lines
of

(let* ((name (buffer-file-name))
       (backend (vc-backend name)))
  (when backend
    (vc-call-backend backend 'repository-url name)))

Obtaining the current branch seems a little harder.  Judging from
describe-function there doesn't seem to be a function in vc-git that
exposes the current branch.  But it should be easy to get by shelling
out to git.

HTH



reply via email to

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