This repository was archived by the owner on Jun 8, 2019. It is now read-only.
forked from gogs/go-gogs-client
-
Notifications
You must be signed in to change notification settings - Fork 53
Status-API #49
Merged
Merged
Status-API #49
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.
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,95 @@ | ||
// Copyright 2017 The Gitea 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 gitea | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"fmt" | ||
"time" | ||
) | ||
|
||
// StatusState holds the state of a Status | ||
// It can be "pending", "success", "error", "failure", and "warning" | ||
type StatusState string | ||
|
||
const ( | ||
// StatusPending is for when the Status is Pending | ||
StatusPending StatusState = "pending" | ||
// StatusSuccess is for when the Status is Success | ||
StatusSuccess StatusState = "success" | ||
// StatusError is for when the Status is Error | ||
StatusError StatusState = "error" | ||
// StatusFailure is for when the Status is Failure | ||
StatusFailure StatusState = "failure" | ||
// StatusWarning is for when the Status is Warning | ||
StatusWarning StatusState = "warning" | ||
) | ||
|
||
// Status holds a single Status of a single Commit | ||
type Status struct { | ||
ID int64 `json:"id"` | ||
State StatusState `json:"status"` | ||
TargetURL string `json:"target_url"` | ||
Description string `json:"description"` | ||
URL string `json:"url"` | ||
Context string `json:"context"` | ||
Creator *User `json:"creator"` | ||
Created time.Time `json:"created_at"` | ||
Updated time.Time `json:"updated_at"` | ||
} | ||
|
||
// CombinedStatus holds the combined state of several statuses for a single commit | ||
type CombinedStatus struct { | ||
State StatusState `json:"state"` | ||
SHA string `json:"sha"` | ||
TotalCount int `json:"total_count"` | ||
Statuses []*Status `json:"statuses"` | ||
Repository *Repository `json:"repository"` | ||
CommitURL string `json:"commit_url"` | ||
URL string `json:"url"` | ||
} | ||
|
||
// CreateStatusOption holds the information needed to create a new Status for a Commit | ||
type CreateStatusOption struct { | ||
State StatusState `json:"state"` | ||
TargetURL string `json:"target_url"` | ||
Description string `json:"description"` | ||
Context string `json:"context"` | ||
} | ||
|
||
// ListStatusesOption holds pagination information | ||
type ListStatusesOption struct { | ||
Page int | ||
} | ||
|
||
// CreateStatus creates a new Status for a given Commit | ||
// | ||
// POST /repos/:owner/:repo/statuses/:sha | ||
func (c *Client) CreateStatus(owner, repo, sha string, opts CreateStatusOption) (*Status, error) { | ||
body, err := json.Marshal(&opts) | ||
if err != nil { | ||
return nil, err | ||
} | ||
status := &Status{} | ||
return status, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/statuses/%s", owner, repo, sha), | ||
jsonHeader, bytes.NewReader(body), status) | ||
} | ||
|
||
// ListStatuses returns all statuses for a given Commit | ||
// | ||
// GET /repos/:owner/:repo/commits/:ref/statuses | ||
func (c *Client) ListStatuses(owner, repo, sha string, opts ListStatusesOption) ([]*Status, error) { | ||
statuses := make([]*Status, 0, 10) | ||
return statuses, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/commits/%s/statuses?page=%d", owner, repo, sha, opts.Page), nil, nil, &statuses) | ||
} | ||
|
||
// GetCombinedStatus returns the CombinedStatus for a given Commit | ||
// | ||
// GET /repos/:owner/:repo/commits/:ref/status | ||
func (c *Client) GetCombinedStatus(owner, repo, sha string) (*CombinedStatus, error) { | ||
status := &CombinedStatus{} | ||
return status, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/commits/%s/status", owner, repo, sha), nil, nil, status) | ||
} |
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.
comment header