-
Notifications
You must be signed in to change notification settings - Fork 124
/
patch_intent.go
105 lines (92 loc) · 3.13 KB
/
patch_intent.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package data
import (
"context"
"net/http"
"github.com/evergreen-ci/evergreen"
mgobson "github.com/evergreen-ci/evergreen/db/mgo/bson"
"github.com/evergreen-ci/evergreen/model"
"github.com/evergreen-ci/evergreen/model/patch"
"github.com/evergreen-ci/evergreen/units"
"github.com/evergreen-ci/gimlet"
"github.com/mongodb/amboy"
"github.com/mongodb/grip"
"github.com/mongodb/grip/message"
"github.com/pkg/errors"
)
// AddPRPatchIntent inserts the intent and adds it to the queue if PR testing is enabled for the branch.
func AddPRPatchIntent(intent patch.Intent, queue amboy.Queue) error {
if err := intent.Insert(); err != nil {
grip.Error(message.WrapError(err, message.Fields{
"message": "couldn't insert patch intent",
"id": intent.ID(),
"type": intent.GetType(),
"requester": intent.RequesterIdentity(),
}))
return gimlet.ErrorResponse{
StatusCode: http.StatusInternalServerError,
Message: "couldn't insert patch intent",
}
}
job := units.NewPatchIntentProcessor(evergreen.GetEnvironment(), mgobson.NewObjectId(), intent)
if err := queue.Put(context.Background(), job); err != nil {
grip.Error(message.WrapError(err, message.Fields{
"source": "GitHub hook",
"message": "GitHub pull request not queued for processing",
"intent_id": intent.ID(),
}))
return gimlet.ErrorResponse{
StatusCode: http.StatusInternalServerError,
Message: "enqueueing patch intent for processing",
}
}
grip.Info(message.Fields{
"message": "GitHub pull request queued",
"intent_type": intent.GetType(),
"intent_id": intent.ID(),
})
return nil
}
func AddGithubMergeIntent(intent patch.Intent, queue amboy.Queue) error {
patchDoc := intent.NewPatch()
projectRef, err := model.FindOneProjectRefWithCommitQueueByOwnerRepoAndBranch(patchDoc.GithubMergeData.Org,
patchDoc.GithubMergeData.Repo, patchDoc.GithubMergeData.BaseBranch)
if err != nil {
return gimlet.ErrorResponse{
StatusCode: http.StatusInternalServerError,
Message: errors.Wrap(err, "finding project ref for GitHub merge group").Error(),
}
}
if projectRef == nil {
return nil
}
if err := intent.Insert(); err != nil {
grip.Error(message.WrapError(err, message.Fields{
"message": "couldn't insert GitHub merge group intent",
"id": intent.ID(),
"type": intent.GetType(),
"requester": intent.RequesterIdentity(),
}))
return gimlet.ErrorResponse{
StatusCode: http.StatusInternalServerError,
Message: "couldn't insert GitHub merge group intent",
}
}
job := units.NewPatchIntentProcessor(evergreen.GetEnvironment(), mgobson.NewObjectId(), intent)
if err := queue.Put(context.Background(), job); err != nil {
grip.Error(message.WrapError(err, message.Fields{
"source": "GitHub hook",
"message": "GitHub merge group not queued for processing",
"intent_id": intent.ID(),
}))
return gimlet.ErrorResponse{
StatusCode: http.StatusInternalServerError,
Message: "enqueueing GitHub merge group for processing",
}
}
grip.Info(message.Fields{
"message": "GitHub merge group queued",
"intent_type": intent.GetType(),
"intent_id": intent.ID(),
})
return nil
}