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
Add API for manipulating Git hooks #156
Merged
Merged
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
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,54 @@ | ||
// Copyright 2019 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" | ||
) | ||
|
||
// GitHook represents a Git repository hook | ||
type GitHook struct { | ||
Name string `json:"name"` | ||
IsActive bool `json:"is_active"` | ||
Content string `json:"content,omitempty"` | ||
} | ||
|
||
// GitHookList represents a list of Git hooks | ||
type GitHookList []*GitHook | ||
|
||
// ListRepoGitHooks list all the Git hooks of one repository | ||
func (c *Client) ListRepoGitHooks(user, repo string) (GitHookList, error) { | ||
hooks := make([]*GitHook, 0, 10) | ||
return hooks, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/hooks/git", user, repo), nil, nil, &hooks) | ||
} | ||
|
||
// GetRepoGitHook get a Git hook of a repository | ||
func (c *Client) GetRepoGitHook(user, repo, id string) (*GitHook, error) { | ||
h := new(GitHook) | ||
return h, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/hooks/git/%s", user, repo, id), nil, nil, h) | ||
zeripath marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
// EditGitHookOption options when modifying one Git hook | ||
type EditGitHookOption struct { | ||
Content string `json:"content"` | ||
} | ||
|
||
// EditRepoGitHook modify one Git hook of a repository | ||
func (c *Client) EditRepoGitHook(user, repo, id string, opt EditGitHookOption) error { | ||
body, err := json.Marshal(&opt) | ||
if err != nil { | ||
return err | ||
} | ||
_, err = c.getResponse("PATCH", fmt.Sprintf("/repos/%s/%s/hooks/git/%s", user, repo, id), jsonHeader, bytes.NewReader(body)) | ||
zeripath marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return err | ||
} | ||
|
||
// DeleteRepoGitHook delete one Git hook from a repository | ||
func (c *Client) DeleteRepoGitHook(user, repo, id string) error { | ||
_, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/hooks/git/%s", user, repo, id), nil, nil) | ||
zeripath marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return err | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.