Function: github-reference

github-reference is a byte-compiled function defined in hib-social.el.

Signature

(github-reference REFERENCE &optional USER PROJECT)

Documentation

Display Github entity associated with REFERENCE and optional USER and PROJECT.

REFERENCE is a string of one of the following forms:
    <ref-item>
    <user>/<project>/<ref-item>
    <project>/<ref-item>
or /<project>.

<ref-item> is one of these:
  one of the words: branches, commits, contributors, issues,
  people or staff, pulls, status or tags; the associated items
  are listed;

  one of the words: branch, commit, issue, pull or tag followed
  by by '/', '-', or '=', and an item-id; the item is shown;

  an issue reference given by a positive integer, e.g. 92 or
  prefaced with GH-, e.g. GH-92; the issue is displayed;

  a commit reference given by a hex number, 55a1f0; the commit
  diff is displayed;

  a filename reference given by an alphanumeric name; the file
  is displayed.

USER defaults to the value of hibtypes-github-default-user. If given, PROJECT overrides any project value in REFERENCE. If no PROJECT value is provided, it defaults to the value of hibtypes-github-default-project.

Source Code

;; Defined in ~/.emacs.d/elpa/hyperbole-20260414.325/hib-social.el
;;; Remote Github commit references

;; Don't make this a defact or its arguments may be improperly expanded as pathnames.
(defun github-reference (reference &optional user project)
  "Display Github entity associated with REFERENCE and optional USER and PROJECT.
REFERENCE is a string of one of the following forms:
    <ref-item>
    <user>/<project>/<ref-item>
    <project>/<ref-item>
or  /<project>.

<ref-item> is one of these:
  one of the words: branches, commits, contributors, issues,
  people or staff, pulls, status or tags; the associated items
  are listed;

  one of the words: branch, commit, issue, pull or tag followed
  by by '/', '-', or '=', and an item-id; the item is shown;

  an issue reference given by a positive integer, e.g. 92 or
  prefaced with GH-, e.g. GH-92; the issue is displayed;

  a commit reference given by a hex number, 55a1f0; the commit
  diff is displayed;

  a filename reference given by an alphanumeric name; the file
  is displayed.

USER defaults to the value of `hibtypes-github-default-user'.
If given, PROJECT overrides any project value in REFERENCE.  If no
PROJECT value is provided, it defaults to the value of
`hibtypes-github-default-project'."
  (cond ((or (null reference) (equal reference ""))
	 (error "(github-reference): Github reference must not be empty"))
	((equal reference "status")
	 (funcall hibtypes-social-display-function "https://status.github.com"))
	(t (let ((case-fold-search t)
		 (url-to-format (assoc-default "github" hibtypes-social-hashtag-alist #'string-match))
		 (ref-type))
	     (when url-to-format
	       (cond ((string-match "\\`\\(branch\\|commit\\|issue\\|pull\\|tag\\)[-/=]" reference)
		      ;; [branch | commit | issue | pull | tag]/ref-item
		      nil)
		     ((string-match "\\`/?\\(\\([^/#@]+\\)/\\)\\([^/#@]+\\)\\'" reference)
		      ;; /?user/project
		      (setq user (or user (match-string-no-properties 2 reference))
			    project (or project (match-string-no-properties 3 reference))
			    reference nil))
		     ((string-match "\\`/?\\(\\([^/#@]+\\)/\\)?\\([^/#@]+\\)/\\([^#@]+\\)\\'" reference)
		      ;; /?[user/]project/ref-item
		      (setq user (or user (match-string-no-properties 2 reference))
			    project (or project (match-string-no-properties 3 reference))
			    reference (match-string-no-properties 4 reference)))
		     ((string-match "\\`/\\([^/#@]+\\)\\'" reference)
		      ;; /project
		      (setq project (or project (match-string-no-properties 1 reference))
			    reference nil)))
	       (when (or (and project (string-match "\\`\\(members\\|people\\|staff\\)\\'" project))
			 ;; Change <org-name>/[members|people|staff] to /orgs/<org-name>/people.
			 (and reference (string-match "\\`\\(members\\|people\\|staff\\)\\'" reference)))
		 ;; Change <org-name>/project/[people|staff] to /orgs/<org-name>/people.
		 (setq project user
		       user "orgs"
		       reference "people"))
	       (when (equal reference "contributors")
		 ;; Change /user/project/contributors to /user/project/graphs/contributors.
		 (setq ref-type "graphs/"
		       reference "contributors"))
	       (unless (stringp user) (setq user hibtypes-github-default-user))
	       (unless (stringp project) (setq project hibtypes-github-default-project))
	       (when reference
		 (cond ((member reference '("branches" "commits" "contributors" "issues" "people" "pulls" "tags"))
			;; All branches, commits, contributors, open issues, people, pull requests or commit tags reference
			(setq ref-type reference
			      reference ""))
		       ((and (< (length reference) 8) (string-match "\\`\\([gG][hH]-\\)?[0-9]+\\'" reference))
			;; Issue 'number' or 'GH-number' ref-id reference
			(setq ref-type "issues/"
			      reference (substring reference (match-end 1) (match-end 0))))
		       ((string-match "\\`\\(commit\\|issue\\|pull\\)[-/=]" reference)
			;; Specific reference preceded by keyword branch, commit,
			;; issue, or pull and followed by -, /, = or #.
			(setq ref-type (substring reference 0 (match-end 1))
			      reference (substring reference (match-end 0))
			      ref-type (concat ref-type (if (string-equal ref-type "issue") "s/" "/"))))
		       ((string-match "\\`[0-9a-f]+\\'" reference)
			;; Commit reference
			(setq ref-type "commit/"))
		       (t
			;; Specific branch or commit tag reference
			(if (string-match "\\`\\(branch\\|tag\\)[-/=]" reference)
			    ;; Reference is a specific branch or tag.
			    ;; If preceded by optional keyword, remove that from the reference.
			    (setq ref-type "blob/"
				  reference (substring reference (match-end 0)))
			  ;; Reference is a file within a branch.
			  (setq ref-type "blob/master/")))))
	       (if (and (stringp user) (stringp project))
		   (funcall hibtypes-social-display-function
			    (if reference
				(format url-to-format user project ref-type reference)
			      ;; Remove trailing /
			      (substring (format url-to-format user project "" "") 0 -1)))
		 (cond ((and (null user) (null project))
			(error "(github-reference): Set `hibtypes-github-default-user' and `hibtypes-github-default-project'"))
		       ((null user)
			(error "(github-reference): Set `hibtypes-github-default-user'"))
		       (t
			(error "(github-reference): Set `hibtypes-github-default-project'")))))
	     (unless url-to-format
	       (error "(github-reference): Add an entry for github to `hibtypes-social-hashtag-alist'"))))))