|
|
|
@@ -50,6 +50,11 @@ type HookPostReceiveBranchResult struct { |
|
|
|
URL string |
|
|
|
} |
|
|
|
|
|
|
|
// HookEnvResult |
|
|
|
type HookEnvResult struct { |
|
|
|
Config map[string]string |
|
|
|
} |
|
|
|
|
|
|
|
// HookPreReceive check whether the provided commits are allowed |
|
|
|
func HookPreReceive(ownerName, repoName string, opts HookOptions) (int, string) { |
|
|
|
reqURL := setting.LocalURL + fmt.Sprintf("api/internal/hook/pre-receive/%s/%s", |
|
|
|
@@ -122,3 +127,28 @@ func SetDefaultBranch(ownerName, repoName, branch string) error { |
|
|
|
} |
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
// GetHookConfig get hook config to set environment for hook script |
|
|
|
func GetHookConfig(ownerName, repoName string) (map[string]string, string) { |
|
|
|
reqURL := setting.LocalURL + fmt.Sprintf("api/internal/hook/env/%s/%s", |
|
|
|
url.PathEscape(ownerName), |
|
|
|
url.PathEscape(repoName), |
|
|
|
) |
|
|
|
|
|
|
|
req := newInternalRequest(reqURL, "GET") |
|
|
|
req = req.Header("Content-Type", "application/json") |
|
|
|
req.SetTimeout(60*time.Second, time.Duration(60)*time.Second) |
|
|
|
resp, err := req.Response() |
|
|
|
if err != nil { |
|
|
|
return nil, fmt.Sprintf("Unable to contact gitea: %v", err.Error()) |
|
|
|
} |
|
|
|
defer resp.Body.Close() |
|
|
|
|
|
|
|
if resp.StatusCode != http.StatusOK { |
|
|
|
return nil, decodeJSONError(resp).Err |
|
|
|
} |
|
|
|
res := &HookEnvResult{} |
|
|
|
_ = json.NewDecoder(resp.Body).Decode(res) |
|
|
|
|
|
|
|
return res.Config, "" |
|
|
|
} |