Skip to content

Commit

Permalink
Enhance generating bitbucket.org links for markdown files.
Browse files Browse the repository at this point in the history
  • Loading branch information
djgoku committed Sep 23, 2024
1 parent 59c0f04 commit 4223fd2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
17 changes: 17 additions & 0 deletions git-link-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,20 @@

(should (equal '("bitbucket.org" "atlassianlabs/atlascode")
(git-link--parse-remote "ssh://bitbucket.org:atlassianlabs/atlascode.git"))))

(ert-deftest git-link-bitbucket ()
(should (equal "https://bitbucket.org/atlassian/atlascode/annotate/a-commit-hash/README.md#README.md-1"
(git-link-bitbucket "bitbucket.org" "atlassian/atlascode" "README.md" "_branch" "a-commit-hash" 1 nil)))

(should (equal "https://bitbucket.org/atlassian/atlascode/annotate/a-commit-hash/README.md#README.md-1:33"
(git-link-bitbucket "bitbucket.org" "atlassian/atlascode" "README.md" "_branch" "a-commit-hash" 1 33)))

(should (equal "https://bitbucket.org/atlassian/atlascode/src/a-commit-hash/.gitignore#.gitignore-1:33"
(git-link-bitbucket "bitbucket.org" "atlassian/atlascode" ".gitignore" "_branch" "a-commit-hash" 1 33))))

(ert-deftest git-link--should-render-via-bitbucket-annotate ()
(should (equal "annotate"
(git-link--should-render-via-bitbucket-annotate "README.md")))

(should (equal "src"
(git-link--should-render-via-bitbucket-annotate "a-cool-new-file.txt"))))
21 changes: 20 additions & 1 deletion git-link.el
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,15 @@ we can prevent that behaviour."
:type 'list
:group 'git-link)

;; https://support.atlassian.com/bitbucket-cloud/docs/readme-content/#Extensions-and-Languages
(defcustom git-link-extensions-rendered-via-bitbucket-annotate '("org" "md" "mkd" "mkdn" "mdown"
"markdown" "text" "rst" "textile"
"asciidoc")
"List of extensions that should be rendered via annotate else
they will actually be rendered. We can prevent that behaviour."
:type 'list
:group 'git-link)

(defun git-link--exec(&rest args)
(ignore-errors
(with-temp-buffer
Expand Down Expand Up @@ -678,9 +687,10 @@ return (FILENAME . REVISION) otherwise nil."

(defun git-link-bitbucket (hostname dirname filename _branch commit start end)
;; ?at=branch-name
(format "https://%s/%s/src/%s/%s"
(format "https://%s/%s/%s/%s/%s"
hostname
dirname
(git-link--should-render-via-bitbucket-annotate filename)
commit
(if (string= "" (file-name-nondirectory filename))
filename
Expand Down Expand Up @@ -800,6 +810,15 @@ shown as a plain file"
(let ((extension (or (file-name-extension filename) "")))
(member (downcase extension) git-link-extensions-rendered-plain)))

(defun git-link--should-render-via-bitbucket-annotate (filename)
"Check if the extension of the given filename belongs
to the list of extensions which generated link should be
shown via annotate in bitbucket."
(let ((extension (or (file-name-extension filename) "")))
(if (member (downcase extension) git-link-extensions-rendered-via-bitbucket-annotate)
"annotate"
"src")))

;;;###autoload
(defun git-link (remote start end)
"Create a URL representing the current buffer's location in its
Expand Down

0 comments on commit 4223fd2

Please sign in to comment.