(c *cli.Context)
| 186 | } |
| 187 | |
| 188 | func 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 | } |
nothing calls this directly
no test coverage detected