Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
62 changes: 62 additions & 0 deletions repo_commits.go
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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm.. you're right!

Email string `json:"email"`
Name string `json:"name"`
When time.Time `json:"when"`
}

type Commit struct {
Copy link
Member

Choose a reason for hiding this comment

The 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)
}
60 changes: 60 additions & 0 deletions repo_releases.go
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)
}