all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* getting current repo info
@ 2021-10-05  4:43 Ag Ibragimov
  2021-10-05  7:30 ` Omar Polo
  2021-10-05  8:07 ` Tassilo Horn
  0 siblings, 2 replies; 3+ messages in thread
From: Ag Ibragimov @ 2021-10-05  4:43 UTC (permalink / raw)
  To: emacs-devel


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?

--
Thanks,
Ag



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: getting current repo info
  2021-10-05  4:43 getting current repo info Ag Ibragimov
@ 2021-10-05  7:30 ` Omar Polo
  2021-10-05  8:07 ` Tassilo Horn
  1 sibling, 0 replies; 3+ messages in thread
From: Omar Polo @ 2021-10-05  7:30 UTC (permalink / raw)
  To: Ag Ibragimov; +Cc: emacs-devel


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



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: getting current repo info
  2021-10-05  4:43 getting current repo info Ag Ibragimov
  2021-10-05  7:30 ` Omar Polo
@ 2021-10-05  8:07 ` Tassilo Horn
  1 sibling, 0 replies; 3+ messages in thread
From: Tassilo Horn @ 2021-10-05  8:07 UTC (permalink / raw)
  To: Ag Ibragimov; +Cc: emacs-devel

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



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-10-05  8:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-10-05  4:43 getting current repo info Ag Ibragimov
2021-10-05  7:30 ` Omar Polo
2021-10-05  8:07 ` Tassilo Horn

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.