-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added git tags support. #51
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright 2013 The go-github AUTHORS. All rights reserved. | ||
// | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package github | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
// GitObject represents a git object. | ||
type GitObject struct { | ||
Type string `json:"type,omitempty"` | ||
SHA string `json:"sha,omitempty"` | ||
URL string `json:"url,omitempty"` | ||
} | ||
|
||
// Tag represents a tag object. | ||
type Tag struct { | ||
Tag string `json:"tag,omitempty"` | ||
SHA string `json:"sha,omitempty"` | ||
URL string `json:"url,omitempty"` | ||
Message string `json:"message,omitempty"` | ||
Tagger *CommitAuthor `json:"tagger,omitempty"` | ||
Object *GitObject `json:"object,omitempty"` | ||
} | ||
|
||
type TagRequest struct { | ||
Tag string | ||
Message string | ||
Object string | ||
Type string | ||
Tagger *CommitAuthor | ||
} | ||
|
||
// GetTag fetchs a tag from a repo given a SHA. | ||
// | ||
// GitHub API docs: http://developer.github.com/v3/git/tags/#get-a-tag | ||
func (s *GitService) GetTag(owner string, repo string, sha string) (*Tag, *Response, error) { | ||
u := fmt.Sprintf("repos/%v/%v/git/tags/%v", owner, repo, sha) | ||
req, err := s.client.NewRequest("GET", u, nil) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
tag := new(Tag) | ||
resp, err := s.client.Do(req, tag) | ||
return tag, resp, err | ||
} | ||
|
||
// CreateTag creates a tag object. | ||
// | ||
// GitHub API docs: http://developer.github.com/v3/git/tags/#create-a-tag-object | ||
func (s *GitService) CreateTag(owner string, repo string, tagRequest *TagRequest) (*Tag, *Response, error) { | ||
u := fmt.Sprintf("repos/%v/%v/git/tags", owner, repo) | ||
req, err := s.client.NewRequest("POST", u, tagRequest) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
t := new(Tag) | ||
resp, err := s.client.Do(req, t) | ||
return t, resp, err | ||
} |
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,65 @@ | ||
// Copyright 2013 The go-github AUTHORS. All rights reserved. | ||
// | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package github | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestGitService_GetTag(t *testing.T) { | ||
setup() | ||
defer teardown() | ||
|
||
mux.HandleFunc("/repos/o/r/git/tags/s", func(w http.ResponseWriter, r *http.Request) { | ||
testMethod(t, r, "GET") | ||
|
||
fmt.Fprint(w, `{"tag": "t"}`) | ||
}) | ||
|
||
tag, _, err := client.Git.GetTag("o", "r", "s") | ||
|
||
if err != nil { | ||
t.Errorf("Git.GetTag returned error: %v", err) | ||
} | ||
|
||
want := &Tag{Tag: "t"} | ||
if !reflect.DeepEqual(tag, want) { | ||
t.Errorf("Git.GetTag returned %+v, want %+v", tag, want) | ||
} | ||
} | ||
|
||
func TestGitService_CreateTag(t *testing.T) { | ||
setup() | ||
defer teardown() | ||
|
||
input := &TagRequest{Tag: "t", Object: "s"} | ||
|
||
mux.HandleFunc("/repos/o/r/git/tags", func(w http.ResponseWriter, r *http.Request) { | ||
v := new(TagRequest) | ||
json.NewDecoder(r.Body).Decode(v) | ||
|
||
testMethod(t, r, "POST") | ||
if !reflect.DeepEqual(v, input) { | ||
t.Errorf("Request body = %+v, want %+v", v, input) | ||
} | ||
|
||
fmt.Fprint(w, `{"tag": "t"}`) | ||
}) | ||
|
||
tag, _, err := client.Git.CreateTag("o", "r", input) | ||
if err != nil { | ||
t.Errorf("Git.CreateTag returned error: %v", err) | ||
} | ||
|
||
want := &Tag{Tag: "t"} | ||
if !reflect.DeepEqual(tag, want) { | ||
t.Errorf("Git.GetTag returned %+v, want %+v", tag, want) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like
Tag
will also need atype
field, which is used just for the create call.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
err, no. Actually it's worse than that. On input, you pass an "object" field which is a string, but on output it's an object. So I guess that means we have to have a separate
TagRequest
(or similarly named) type /facepalm