Skip to content

Commit 2107af1

Browse files
authored
Merge pull request #128 from djgoku/chore/add-bitbucket-tests
Chore/add bitbucket tests
2 parents a0a2fff + 4223fd2 commit 2107af1

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

git-link-test.el

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,27 @@
6565
(git-link--parse-remote "ssh://git-codecommit.us-west-2.amazonaws.com/v1/repos/TestRepo")))
6666

6767
(should (equal '("go.googlesource.com" "go")
68-
(git-link--parse-remote "https://go.googlesource.com/go"))))
68+
(git-link--parse-remote "https://go.googlesource.com/go")))
69+
70+
(should (equal '("bitbucket.org" "atlassianlabs/atlascode")
71+
(git-link--parse-remote "https://bitbucket.org/atlassianlabs/atlascode.git")))
72+
73+
(should (equal '("bitbucket.org" "atlassianlabs/atlascode")
74+
(git-link--parse-remote "ssh://bitbucket.org:atlassianlabs/atlascode.git"))))
75+
76+
(ert-deftest git-link-bitbucket ()
77+
(should (equal "https://bitbucket.org/atlassian/atlascode/annotate/a-commit-hash/README.md#README.md-1"
78+
(git-link-bitbucket "bitbucket.org" "atlassian/atlascode" "README.md" "_branch" "a-commit-hash" 1 nil)))
79+
80+
(should (equal "https://bitbucket.org/atlassian/atlascode/annotate/a-commit-hash/README.md#README.md-1:33"
81+
(git-link-bitbucket "bitbucket.org" "atlassian/atlascode" "README.md" "_branch" "a-commit-hash" 1 33)))
82+
83+
(should (equal "https://bitbucket.org/atlassian/atlascode/src/a-commit-hash/.gitignore#.gitignore-1:33"
84+
(git-link-bitbucket "bitbucket.org" "atlassian/atlascode" ".gitignore" "_branch" "a-commit-hash" 1 33))))
85+
86+
(ert-deftest git-link--should-render-via-bitbucket-annotate ()
87+
(should (equal "annotate"
88+
(git-link--should-render-via-bitbucket-annotate "README.md")))
89+
90+
(should (equal "src"
91+
(git-link--should-render-via-bitbucket-annotate "a-cool-new-file.txt"))))

git-link.el

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,15 @@ we can prevent that behaviour."
304304
:type 'list
305305
:group 'git-link)
306306

307+
;; https://support.atlassian.com/bitbucket-cloud/docs/readme-content/#Extensions-and-Languages
308+
(defcustom git-link-extensions-rendered-via-bitbucket-annotate '("org" "md" "mkd" "mkdn" "mdown"
309+
"markdown" "text" "rst" "textile"
310+
"asciidoc")
311+
"List of extensions that should be rendered via annotate else
312+
they will actually be rendered. We can prevent that behaviour."
313+
:type 'list
314+
:group 'git-link)
315+
307316
(defun git-link--exec(&rest args)
308317
(ignore-errors
309318
(with-temp-buffer
@@ -678,9 +687,10 @@ return (FILENAME . REVISION) otherwise nil."
678687

679688
(defun git-link-bitbucket (hostname dirname filename _branch commit start end)
680689
;; ?at=branch-name
681-
(format "https://%s/%s/src/%s/%s"
690+
(format "https://%s/%s/%s/%s/%s"
682691
hostname
683692
dirname
693+
(git-link--should-render-via-bitbucket-annotate filename)
684694
commit
685695
(if (string= "" (file-name-nondirectory filename))
686696
filename
@@ -800,6 +810,15 @@ shown as a plain file"
800810
(let ((extension (or (file-name-extension filename) "")))
801811
(member (downcase extension) git-link-extensions-rendered-plain)))
802812

813+
(defun git-link--should-render-via-bitbucket-annotate (filename)
814+
"Check if the extension of the given filename belongs
815+
to the list of extensions which generated link should be
816+
shown via annotate in bitbucket."
817+
(let ((extension (or (file-name-extension filename) "")))
818+
(if (member (downcase extension) git-link-extensions-rendered-via-bitbucket-annotate)
819+
"annotate"
820+
"src")))
821+
803822
;;;###autoload
804823
(defun git-link (remote start end)
805824
"Create a URL representing the current buffer's location in its

0 commit comments

Comments
 (0)