Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

openRepository opens remote branch tree urls by default #69

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions lib/github-file.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ class GitHubFile
openRepository: ->
@isOpenable().then (isOpenable) =>
if isOpenable
@gitHubRepoUrl().then (gitHubRepoUrl) =>
@openUrlInBrowser(gitHubRepoUrl)
@treeUrl().then (treeUrl) =>
@openUrlInBrowser(treeUrl)
else
@reportValidationErrors()

Expand Down Expand Up @@ -170,6 +170,14 @@ class GitHubFile
.then ([gitHubRepoUrl, branchName]) =>
"#{gitHubRepoUrl}/compare/#{@encodeSegments(branchName)}"

treeUrl: ->
Promise.all([@gitHubRepoUrl(), @remoteBranchName()])
.then ([gitHubRepoUrl, remoteBranchName]) ->
if remoteBranchName isnt 'master'
"#{gitHubRepoUrl}/tree/#{remoteBranchName}"
else
gitHubRepoUrl

encodeSegments: (segments='') ->
segments = segments.split('/')
segments = segments.map (segment) -> encodeURIComponent(segment)
Expand Down
1 change: 1 addition & 0 deletions spec/fixtures/some-branch.git/HEAD
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ref: refs/heads/some-branch
13 changes: 13 additions & 0 deletions spec/fixtures/some-branch.git/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = false
[remote "origin"]
url = https://github.com/some-user/some-repo.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "some-branch"]
remote = origin
merge = refs/heads/some-branch
Binary file added spec/fixtures/some-branch.git/index
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
x��A�0@Q�=�\@S�� 1nu�ʴ�5@��ܾ��\��4�d���G�6$�MH����(-sr� *�J� �����XC��g����O�O\� 4��\g\Kp�g�զ�X� u��?��R_�@�
Expand Down
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions spec/fixtures/some-branch.git/refs/heads/some-branch
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
80b7897ceb6bd7531708509b50afeab36a4b73fd
32 changes: 32 additions & 0 deletions spec/github-file-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,38 @@ describe "GitHubFile", ->
runs -> expect(githubFile.openUrlInBrowser).toHaveBeenCalledWith \
'https://github.com/some-user/some-repo'

describe "when the branch is not master", ->
fixtureName = 'some-branch'

beforeEach ->
setupWorkingDir(fixtureName)
setupGithubFile()

afterEach ->
teardownWorkingDirAndRestoreFixture(fixtureName)

it "opens the GitHub.com tree URL for the branch", ->
spyOn(githubFile, 'openUrlInBrowser')
waitsForPromise -> githubFile.openRepository()
runs -> expect(githubFile.openUrlInBrowser).toHaveBeenCalledWith \
'https://github.com/some-user/some-repo/tree/some-branch'

describe "when the local branch is not tracked", ->
fixtureName = 'non-tracked-branch'

beforeEach ->
setupWorkingDir(fixtureName)
setupGithubFile()

afterEach ->
teardownWorkingDirAndRestoreFixture(fixtureName)

it "opens the GitHub.com reposiotry URL", ->
spyOn(githubFile, 'openUrlInBrowser')
waitsForPromise -> githubFile.openRepository()
runs -> expect(githubFile.openUrlInBrowser).toHaveBeenCalledWith \
'https://github.com/some-user/some-repo'

describe "openIssues", ->
describe 'when the file is openable on GitHub.com', ->
fixtureName = 'github-remote'
Expand Down