Function: gitlab-reference
gitlab-reference is a byte-compiled function defined in hib-social.el.
Signature
(gitlab-reference REFERENCE &optional USER PROJECT)
Documentation
Display Gitlab 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>
/<group>/<project>
or /<project-or-group> (where a group is a collection of projects).
<ref-item> is one of these:
one of the words: activity, analytics, boards or kanban,
branches, commits, contributors, groups, issues or list, jobs,
labels, merge_requests, milestones, pages, pipelines,
pipeline_charts, members or people or staff, projects, pulls,
schedules, snippets, status or tags; the associated items are
listed;
one of the words: branch, commit(s), issue(s), milestone(s),
pull(s), snippet(s) or tag(s) followed by a '/', '-' or '='
and an item-id; the item is shown;
an issue reference given by a positive integer, e.g. 92 or
prefaced with GL-, e.g. GL-92; the issue is displayed;
a commit reference given by a hex number, 55a1f0; the commit
diff is displayed;
a branch or tag reference given by an alphanumeric name,
e.g. hyper20; the files in the branch are listed.
USER defaults to the value of hibtypes-gitlab-default-user.
If given, PROJECT overrides any project value in REFERENCE. If no
PROJECT value is provided, it defaults to the value of
hibtypes-gitlab-default-project.
Source Code
;; Defined in ~/.emacs.d/elpa/hyperbole-20260414.325/hib-social.el
;;; Remote Gitlab commit references
;; Don't make this a defact or its arguments may be improperly expanded as pathnames.
(defun gitlab-reference (reference &optional user project)
"Display Gitlab 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>
/<group>/<project>
or /<project-or-group> (where a group is a collection of projects).
<ref-item> is one of these:
one of the words: activity, analytics, boards or kanban,
branches, commits, contributors, groups, issues or list, jobs,
labels, merge_requests, milestones, pages, pipelines,
pipeline_charts, members or people or staff, projects, pulls,
schedules, snippets, status or tags; the associated items are
listed;
one of the words: branch, commit(s), issue(s), milestone(s),
pull(s), snippet(s) or tag(s) followed by a '/', '-' or '='
and an item-id; the item is shown;
an issue reference given by a positive integer, e.g. 92 or
prefaced with GL-, e.g. GL-92; the issue is displayed;
a commit reference given by a hex number, 55a1f0; the commit
diff is displayed;
a branch or tag reference given by an alphanumeric name,
e.g. hyper20; the files in the branch are listed.
USER defaults to the value of `hibtypes-gitlab-default-user'.
If given, PROJECT overrides any project value in REFERENCE. If no
PROJECT value is provided, it defaults to the value of
`hibtypes-gitlab-default-project'."
(cond ((or (null reference) (equal reference ""))
(error "(gitlab-reference): Gitlab reference must not be empty"))
((equal reference "status")
(funcall hibtypes-social-display-function "https://status.gitlab.com"))
(t (let ((case-fold-search t)
(url-to-format (assoc-default "gitlab" hibtypes-social-hashtag-alist #'string-match))
(ref-type))
(when url-to-format
(cond ((string-match "\\`\\(branch\\|commits?\\|issues?\\milestones?\\|pulls?\\|snippets?\\|tags?\\)[/=]" reference)
;; Reference to a specific 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 (and (null (and user project)) (string-match "\\`\\(groups\\|projects\\)\\'" reference))
;; List all available groups of projects or projects.
(setq user "explore"
project (match-string-no-properties 1 reference)
ref-type nil
reference nil))
(unless (stringp user) (setq user hibtypes-gitlab-default-user))
(unless (stringp project) (setq project hibtypes-gitlab-default-project))
(when (equal project "pages")
;; Project web pages use a reverse pages/<project> URL format
(setq project user
user "pages"
ref-type nil
reference nil))
(when reference
(cond ((string-match "\\`\\(analytics\\|cycle_analytics\\)\\'" reference)
;; Project analytics
(setq ref-type "cycle_analytics"
reference ""))
((string-match "\\`\\(boards\\|kanban\\)\\'" reference)
;; Kanban-type Issue Stage Boards
(setq ref-type "boards"
reference ""))
((equal reference "jobs")
;; Manual/automated project-related jobs that run
(setq ref-type "-/jobs"
reference ""))
((equal reference "list")
;; List all issues
(setq ref-type "issues"
reference ""))
((equal reference "contributors")
(setq ref-type "graphs/master"
reference ""))
((string-match "\\`\\(members\\|people\\|staff\\)\\'" reference)
(setq ref-type "project_members"
reference ""))
((equal reference "pipeline_charts")
;; Continuous Integration Pipeline Charts
(setq ref-type "pipelines/charts"
reference ""))
((equal reference "pulls")
;; Merge requests for the project
(setq ref-type "merge_requests"
reference ""))
((equal reference "schedules")
;; Schedules for CI Pipelines
(setq ref-type "pipeline_schedules"
reference ""))
((string-match "\\`\\(service\\|service_desk\\)\\'" reference)
;; Project help desk
(setq ref-type "issues/service_desk"
reference ""))
((member reference '("activity" "branches" "commits" "issues" "labels"
"merge_requests" "milestones" "pages" "pipelines"
"snippets" "tags"))
;; All activity, branches, commits, cycle analytics, open issues, issue labels,
;; members, merge requests, milestones, web pages, pull requests, code snippets
;; or commit tags reference
(setq ref-type reference
reference ""))
((and (< (length reference) 8) (string-match "\\`\\([gG][lL]-\\)?[0-9]+\\'" reference))
;; Issue ref-id reference
(setq ref-type "issues/"
reference (substring reference (match-end 1) (match-end 0))))
((string-match "\\`label[/=]" reference)
;; Labeled category of issues
(setq ref-type "issues?label_name%5B%5D="
reference (substring reference (match-end 0))))
((string-match "\\`\\(commit\\|issues\\|milestones\\|pull\\|snippets\\|tags\\)[-/=]" reference)
;; Ref-id preceded by a keyword
(setq ref-type (concat (substring reference 0 (match-end 1)) "/")
reference (substring reference (match-end 0))))
((string-match "\\`\\(issue\\|milestone\\|snippet\\|tag\\)[-/=]" reference)
;; Ref-id preceded by a singular keyword that must be converted to plural
(setq ref-type (concat (substring reference 0 (match-end 1)) "s/")
reference (substring reference (match-end 0))))
((string-match "\\`\\(commit\\|pull\\)s[-/=]" reference)
;; Ref-id preceded by a plural keyword that must be converted to singular
(setq ref-type (concat (substring reference 0 (match-end 1)) "/")
reference (substring reference (1+ (match-end 0)))))
((string-match "\\`[0-9a-f]+\\'" reference)
;; Commit reference
(setq ref-type "commit/"))
(t
;; Specific branch or commit tag reference
(setq ref-type "tree/")
(when (string-match "\\`\\(branch\\|tag\\)[-/=]" reference)
;; If preceded by optional keyword, remove that from the reference.
(setq reference (substring reference (match-end 0)))))))
(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 "(gitlab-reference): Set `hibtypes-gitlab-default-user' and `hibtypes-gitlab-default-project'"))
((null user)
(error "(gitlab-reference): Set `hibtypes-gitlab-default-user'"))
(t
(error "(gitlab-reference): Set `hibtypes-gitlab-default-project'")))))
(unless url-to-format
(error "(gitlab-reference): Add an entry for gitlab to `hibtypes-social-hashtag-alist'"))))))