Skip to content

Commit

Permalink
URL can be given for a repo
Browse files Browse the repository at this point in the history
  • Loading branch information
Robb Shecter committed Dec 26, 2015
1 parent ab14908 commit 895b6c7
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 11 deletions.
16 changes: 16 additions & 0 deletions lib/github.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/repo.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 9 additions & 4 deletions lib/spec/test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions src/github.coffee
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
# Utility functions for working with the GitHub API
class App.Github

@parseRepoInput: (text) ->
if @isRepoSpec(text)
text.split('/')
else if @isUrl(text)
matches = text.match(/^https:\/\/github.com\/([^/]+)\/([^/]+)/)
[matches[1], matches[2]]
else
null


@isUrl: (text) ->
/^https:\/\/github.com\/[^/]+\/[^/]+/.test(text)


@isRepoSpec: (text) ->
/^[^/]+\/[^/]+$/.test(text)


@rateLimit: (callback) ->
App.octo.rateLimit.fetch (err, data) ->
if err
Expand Down
5 changes: 3 additions & 2 deletions src/repo.coffee
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
class App.Repo
# @param repo_spec should be a string like "facebook/react"
# @param repo_spec should be a string like "facebook/react" or a GitHub
# project URL.
constructor: (repo_spec, @repoCallback, @issuesCallback, network = true) ->
[@acct, @name] = repo_spec.split('/')
[@acct, @name] = App.Github.parseRepoInput(repo_spec)
@rawdata = {}
@fetchData() if network

Expand Down
12 changes: 8 additions & 4 deletions test/spec/test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -126,24 +126,28 @@ describe "App.Github", ->

describe ".isRepoSpec()", ->

xit "recognizes a valid spec", ->
it "recognizes a valid spec", ->
validSpec = 'dogweather/repo-health-check'
expect( App.Github.isRepoSpec(validSpec) ).toBe true

xit "rejects a string with two /'s", ->
it "rejects a string with two /'s", ->
inValidSpec = '/dogweather/repo-health-check'
expect( App.Github.isRepoSpec(inValidSpec) ).toBe false

describe ".parseRepoInput()", ->

xit "parses a project URL", ->
it "parses a project URL", ->
validUrl = 'https://github.com/dogweather/repo-health-check'
[acct, name] = App.Github.parseRepoInput(validUrl)
expect( acct ).toEqual 'dogweather'
expect( name ).toEqual 'repo-health-check'

xit "parses a repo spec", ->
it "parses a repo spec", ->
validSpec = 'dogweather/repo-health-check'
[acct, name] = App.Github.parseRepoInput(validSpec)
expect( acct ).toEqual 'dogweather'
expect( name ).toEqual 'repo-health-check'

it "returns null if input is neither a URL or repo spec", ->
inValidSpec = '/dogweather/repo-health-check'
expect( App.Github.parseRepoInput(inValidSpec) ).toBe null

0 comments on commit 895b6c7

Please sign in to comment.