MCPcopy Create free account
hub / github.com/gogs/gogs / runHookPostReceive

Function runHookPostReceive

internal/cmd/hook.go:188–270  ·  view source on GitHub ↗
(c *cli.Context)

Source from the content-addressed store, hash-verified

186}
187
188func runHookPostReceive(c *cli.Context) error {
189 if os.Getenv("SSH_ORIGINAL_COMMAND") == "" {
190 return nil
191 }
192 setup(c, "post-receive.log", true)
193
194 // Post-receive hook does more than just gather Git information,
195 // so we need to setup additional services for email notifications.
196 email.NewContext()
197
198 isWiki := strings.Contains(os.Getenv(database.EnvRepoCustomHooksPath), ".wiki.git/")
199
200 buf := bytes.NewBuffer(nil)
201 scanner := bufio.NewScanner(os.Stdin)
202 for scanner.Scan() {
203 buf.Write(scanner.Bytes())
204 buf.WriteByte('\n')
205
206 // TODO: support news feeds for wiki
207 if isWiki {
208 continue
209 }
210
211 fields := bytes.Fields(scanner.Bytes())
212 if len(fields) != 3 {
213 continue
214 }
215
216 options := database.PushUpdateOptions{
217 OldCommitID: string(fields[0]),
218 NewCommitID: string(fields[1]),
219 FullRefspec: string(fields[2]),
220 PusherID: com.StrTo(os.Getenv(database.EnvAuthUserID)).MustInt64(),
221 PusherName: os.Getenv(database.EnvAuthUserName),
222 RepoUserName: os.Getenv(database.EnvRepoOwnerName),
223 RepoName: os.Getenv(database.EnvRepoName),
224 }
225 if err := database.PushUpdate(options); err != nil {
226 log.Error("PushUpdate: %v", err)
227 }
228
229 // Ask for running deliver hook and test pull request tasks
230 q := make(url.Values)
231 q.Add("branch", git.RefShortName(options.FullRefspec))
232 q.Add("secret", os.Getenv(database.EnvRepoOwnerSaltMd5))
233 q.Add("pusher", os.Getenv(database.EnvAuthUserID))
234 reqURL := fmt.Sprintf("%s%s/%s/tasks/trigger?%s", conf.Server.LocalRootURL, options.RepoUserName, options.RepoName, q.Encode())
235 log.Trace("Trigger task: %s", reqURL)
236
237 resp, err := httplib.Get(reqURL).
238 SetTLSClientConfig(&tls.Config{
239 InsecureSkipVerify: true,
240 }).Response()
241 if err == nil {
242 _ = resp.Body.Close()
243 if resp.StatusCode/100 != 2 {
244 log.Error("Failed to trigger task: unsuccessful response code %d", resp.StatusCode)
245 }

Callers

nothing calls this directly

Calls 14

NewContextFunction · 0.92
PushUpdateFunction · 0.92
GetFunction · 0.92
IsWindowsRuntimeFunction · 0.92
RepoPathFunction · 0.92
setupFunction · 0.85
stringFunction · 0.85
WriteMethod · 0.80
BytesMethod · 0.80
AddMethod · 0.80
ResponseMethod · 0.80
SetTLSClientConfigMethod · 0.80

Tested by

no test coverage detected