diff options
Diffstat (limited to 'modules/private/hook.go')
-rw-r--r-- | modules/private/hook.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/modules/private/hook.go b/modules/private/hook.go index 178500f736..cb8fe25708 100644 --- a/modules/private/hook.go +++ b/modules/private/hook.go @@ -5,6 +5,7 @@ package private import ( + "encoding/json" "fmt" "net/http" "net/url" @@ -57,6 +58,12 @@ type HookOptions struct { IsDeployKey bool } +// SSHLogOption ssh log options +type SSHLogOption struct { + IsError bool + Message string +} + // HookPostReceiveResult represents an individual result from PostReceive type HookPostReceiveResult struct { Results []HookPostReceiveBranchResult @@ -146,3 +153,27 @@ func SetDefaultBranch(ownerName, repoName, branch string) error { } return nil } + +// SSHLog sends ssh error log response +func SSHLog(isErr bool, msg string) error { + reqURL := setting.LocalURL + "api/internal/ssh/log" + req := newInternalRequest(reqURL, "POST") + req = req.Header("Content-Type", "application/json") + + jsonBytes, _ := json.Marshal(&SSHLogOption{ + IsError: isErr, + Message: msg, + }) + req.Body(jsonBytes) + + req.SetTimeout(60*time.Second, 60*time.Second) + resp, err := req.Response() + if err != nil { + return fmt.Errorf("unable to contact gitea: %v", err) + } + defer resp.Body.Close() + if resp.StatusCode != http.StatusOK { + return fmt.Errorf("Error returned from gitea: %v", decodeJSONError(resp).Err) + } + return nil +} |