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

Commit

Permalink
Add open pull requests command
Browse files Browse the repository at this point in the history
  • Loading branch information
stephentuso authored and Wliu committed Nov 2, 2017
1 parent 846e2df commit 16bd33e
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ When editing a file in Atom, use the command palette or keyboard shortcuts to:
- Open the blame view for the file on github.com <kbd>alt-g, b</kbd>
- Open the history view for the file on github.com <kbd>alt-g, h</kbd>
- Open the issues view for the repository the file belongs to on github.com <kbd>alt-g, i</kbd>
- Open the pull requests view for the repository the file belongs to on github.com <kbd>alt-g, p</kbd>
- Open the compare page for the current branch on github.com <kbd>alt-g, r</kbd>
- Copy the github.com URL for the currently selected lines <kbd>alt-g, c</kbd>

Expand Down
1 change: 1 addition & 0 deletions keymaps/to-the-hubs.cson
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
'alt-g b': 'open-on-github:blame'
'alt-g h': 'open-on-github:history'
'alt-g i': 'open-on-github:issues'
'alt-g p': 'open-on-github:pull-requests'
'alt-g c': 'open-on-github:copy-url'
'alt-g r': 'open-on-github:branch-compare'
'alt-g g': 'open-on-github:repository'
13 changes: 13 additions & 0 deletions lib/github-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ export default class GitHubFile {
}
}

openPullRequests () {
if (this.isOpenable()) {
return this.openUrlInBrowser(this.pullRequestsUrl())
} else {
return this.reportValidationErrors()
}
}

openRepository () {
if (this.isOpenable()) {
return this.openUrlInBrowser(this.githubRepoUrl())
Expand Down Expand Up @@ -179,6 +187,11 @@ export default class GitHubFile {
return `${this.githubRepoUrl()}/issues`
}

// Internal
pullRequestsUrl () {
return `${this.githubRepoUrl()}/pulls`
}

// Internal
branchCompareUrl () {
return `${this.githubRepoUrl()}/compare/${this.encodeSegments(this.branchName())}`
Expand Down
8 changes: 8 additions & 0 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ module.exports = {
}
},

'open-on-github:pull-requests': () => {
let itemPath = getActivePath()

if (itemPath) {
return GitHubFile.fromPath(itemPath).openPullRequests()
}
},

'open-on-github:copy-url': () => {
const itemPath = getActivePath()

Expand Down
1 change: 1 addition & 0 deletions menus/open-on-github.cson
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
{ 'label': 'File on Master', 'command': 'open-on-github:file-on-master' }
{ 'label': 'History', 'command': 'open-on-github:history' }
{ 'label': 'Issues', 'command': 'open-on-github:issues' }
{ 'label': 'Pull Requests', 'command': 'open-on-github:pull-requests' }
{ 'label': 'Repository', 'command': 'open-on-github:repository' }
]
]
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"open-on-github:file",
"open-on-github:history",
"open-on-github:issues",
"open-on-github:pull-requests",
"open-on-github:repository"
]
},
Expand Down
19 changes: 19 additions & 0 deletions spec/github-file-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,25 @@ describe('GitHubFile', function () {
})
})
})

describe('openPullRequests', () => {
describe('when the file is openable on GitHub.com', () => {
let fixtureName = 'github-remote'

beforeEach(() => {
setupWorkingDir(fixtureName)
setupGithubFile()
})

afterEach(() => teardownWorkingDirAndRestoreFixture(fixtureName))

it('opens the GitHub.com pull requests URL', () => {
spyOn(githubFile, 'openUrlInBrowser')
githubFile.openPullRequests()
expect(githubFile.openUrlInBrowser).toHaveBeenCalledWith('https://github.com/some-user/some-repo/pulls')
})
})
})
})

describe('githubRepoUrl', () => {
Expand Down

0 comments on commit 16bd33e

Please sign in to comment.