This repository has been archived by the owner on Jun 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #95 from dannysperling/gitignore_templates
Add gitignore endpoint for templates
- Loading branch information
Showing
5 changed files
with
95 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "C", | ||
"source": "# Object files\n*.o\n\n# Libraries\n*.lib\n*.a\n\n# Shared objects (inc. Windows DLLs)\n*.dll\n*.so\n*.so.*\n*.dylib\n\n# Executables\n*.exe\n*.out\n*.app\n" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[ | ||
"Actionscript", | ||
"Android", | ||
"AppceleratorTitanium", | ||
"Autotools", | ||
"Bancha", | ||
"C", | ||
"C++" | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package octokit | ||
|
||
// GitIgnoreURL is an address for accessing various templates to apply | ||
// to a repository upon creation. | ||
var GitIgnoreURL = Hyperlink("/gitignore/templates{/name}") | ||
|
||
// GitIgnore creates a GitIgnoreService to access gitignore templates | ||
func (c *Client) GitIgnore() *GitIgnoreService { | ||
return &GitIgnoreService{client: c} | ||
} | ||
|
||
// A service to return gitignore templates | ||
type GitIgnoreService struct { | ||
client *Client | ||
} | ||
|
||
// All gets a list all the available templates | ||
func (s *GitIgnoreService) All(uri *Hyperlink) (templates []string, result *Result) { | ||
if uri == nil { | ||
uri = &GitIgnoreURL | ||
} | ||
url, err := uri.Expand(nil) | ||
if err != nil { | ||
return make([]string, 0), &Result{Err: err} | ||
} | ||
result = s.client.get(url, &templates) | ||
return | ||
} | ||
|
||
// One gets a specific gitignore template based on the passed url | ||
func (s *GitIgnoreService) One(uri *Hyperlink, params M) (template GitIgnoreTemplate, result *Result) { | ||
if uri == nil { | ||
uri = &GitIgnoreURL | ||
} | ||
url, err := uri.Expand(params) | ||
if err != nil { | ||
return GitIgnoreTemplate{}, &Result{Err: err} | ||
} | ||
result = s.client.get(url, &template) | ||
return | ||
} | ||
|
||
//GitIgnoreTemplate is a representation of a given template returned by the service | ||
type GitIgnoreTemplate struct { | ||
Name string `json:"name,omitempty"` | ||
Source string `json:"source,omitempty"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package octokit | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestGitIgnoreService_All(t *testing.T) { | ||
setup() | ||
defer tearDown() | ||
|
||
stubGet(t, "/gitignore/templates", "git_ignore_templates", nil) | ||
|
||
templates, result := client.GitIgnore().All(nil) | ||
assert.False(t, result.HasError()) | ||
assert.Equal(t, "AppceleratorTitanium", templates[2]) | ||
assert.Equal(t, "Autotools", templates[3]) | ||
assert.Len(t, templates, 7) | ||
} | ||
|
||
func TestGitIgnoreService_One(t *testing.T) { | ||
setup() | ||
defer tearDown() | ||
|
||
stubGet(t, "/gitignore/templates/C", "git_ignore_c_template", nil) | ||
|
||
template, result := client.GitIgnore().One(&GitIgnoreURL, M{"name": "C"}) | ||
assert.False(t, result.HasError()) | ||
assert.Equal(t, "C", template.Name) | ||
assert.Equal(t, "# Object files\n*.o\n\n# Libraries\n*.lib\n*.a\n\n# Shared objects (inc. Windows DLLs)\n*.dll\n*.so\n*.so.*\n*.dylib\n\n# Executables\n*.exe\n*.out\n*.app\n", template.Source) | ||
} |