- Notifications
You must be signed in to change notification settings - Fork 148
Api extentions: Client #4
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
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits Select commit Hold shift + click to select a range
fd43787
repo commits client and repo releases client
kiliit 1a3306e
removed unnecessary fields
kiliit 0bfe8f9
some fixes
kiliit 7cc97a8
git diff models
kiliit 9f510d0
changed file and line type to strings
kiliit 463f6d1
changed commit HEAD to use Sha1 type
kiliit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,62 @@ | ||
// Copyright 2014 The Gogs Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
| ||
package gogs | ||
| ||
import ( | ||
"fmt" | ||
"time" | ||
) | ||
| ||
type Sha1 struct { | ||
Sha1 string `json:"sha1"` | ||
} | ||
| ||
type Signature struct { | ||
Email string `json:"email"` | ||
Name string `json:"name"` | ||
When time.Time `json:"when"` | ||
} | ||
| ||
type Commit struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. | ||
ID string `json:"id"` | ||
Author Signature `json:"author"` | ||
Committer Signature `json:"committer"` | ||
CommitMessage string `json:"commit_message"` | ||
} | ||
| ||
type DiffLine struct { | ||
LeftIdx int `json:"left_idx"` | ||
RightIdx int `json:"right_idx"` | ||
Type string `json:"type"` | ||
Content string `json:"content"` | ||
} | ||
| ||
type DiffSection struct { | ||
Name string `json:"name"` | ||
Lines []*DiffLine `json:"lines"` | ||
} | ||
| ||
type DiffFile struct { | ||
Name string `json:"name"` | ||
Index int `json:"index"` | ||
Addition int `json:"addition"` | ||
Deletion int `json:"deletion"` | ||
Type string `json:"type"` | ||
IsCreated bool `json:"created"` | ||
IsDeleted bool `json:"deleted"` | ||
IsBin bool `json:"bin"` | ||
Sections []*DiffSection `json:"sections"` | ||
} | ||
| ||
type Diff struct { | ||
TotalAddition int `json:"total_addition"` | ||
TotalDeletion int `json:"total_deletion"` | ||
Files []*DiffFile `json:"files"` | ||
} | ||
| ||
func (c *Client) CommitByID(user, repo, id string) (*Commit, error) { | ||
commit := new(Commit) | ||
return commit, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/commits/%s", user, repo, id), nil, nil, commit) | ||
} |
This file contains hidden or 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,60 @@ | ||
// Copyright 2014 The Gogs Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
| ||
package gogs | ||
| ||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
"time" | ||
) | ||
| ||
type Release struct { | ||
ID int64 `json:"id"` | ||
Publisher User `json:"publisher"` | ||
TagName string `json:"tag_name"` | ||
LowerTagName string `json:"lower_tag_name"` | ||
Target string `json:"target"` | ||
Title string `json:"title"` | ||
Sha1 string `json:"sha1"` | ||
NumCommits int `json:"num_commits"` | ||
NumCommitsBehind int `json:"num_commits_behind"` | ||
Note string `json:"note"` | ||
IsDraft bool `json:"draft"` | ||
IsPrerelease bool `json:"prerelease"` | ||
Created time.Time `json:"created"` | ||
} | ||
| ||
func (c *Client) ReleaseByName(user, repo, name string) (*Release, error) { | ||
release := new(Release) | ||
return release, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/releases/%s", user, repo, name), nil, nil, release) | ||
} | ||
| ||
func (c *Client) ListReleases() ([]*Release, error) { | ||
releases := make([]*Release, 0, 10) | ||
err := c.getParsedResponse("GET", "/repos/%s/%s/releases", nil, nil, &releases) | ||
return releases, err | ||
} | ||
| ||
type CreateReleaseOption struct { | ||
TagName string `json:"tag_name"` | ||
Target string `json:"target"` | ||
Title string `json:"title"` | ||
Note string `json:"note"` | ||
IsDraft bool `json:"draft"` | ||
IsPrerelease bool `json:"prerelease"` | ||
} | ||
| ||
| ||
func (c *Client) CreateRelease(user string, repo string, opt CreateReleaseOption) (*Release, error) { | ||
body, err := json.Marshal(&opt) | ||
if err != nil { | ||
return nil, err | ||
} | ||
release := new(Release) | ||
return release, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/releases", user, repo), | ||
http.Header{"content-type": []string{"application/json"}}, bytes.NewReader(body), release) | ||
} |
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 is same as https://github.com/gogits/go-gogs-client/blob/master/repo_hooks.go#L75
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.
I think it is better to have a seperation between the webhooks and the commit models. It would be easier to extend them in the future.
And payload author is not exactly the same as a commit signature.
You could have commits from local users that does not have a user on gogs. And payload author lacks the when field.
What do you think?
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.
Hmm.. you're right!