mirror of https://github.com/harness/drone.git
feat: [CODE-3293]: Add create compound label activity on PR creation label assignments (#3603)
* Add PullRequestActivityLabelBase * Merge remote-tracking branch 'origin/main' into dd/compound-label-activity * Add create compound label activity on PR creation label assignmentsmain
parent
a6985a55ad
commit
cc2a63b797
|
@ -107,13 +107,15 @@ func activityPayload(out *label.AssignToPullReqOut) *types.PullRequestActivityLa
|
|||
}
|
||||
|
||||
return &types.PullRequestActivityLabel{
|
||||
Label: out.Label.Key,
|
||||
LabelColor: out.Label.Color,
|
||||
LabelScope: out.Label.Scope,
|
||||
Value: value,
|
||||
ValueColor: valueColor,
|
||||
OldValue: oldValue,
|
||||
OldValueColor: oldValueColor,
|
||||
Type: out.ActivityType,
|
||||
PullRequestActivityLabelBase: types.PullRequestActivityLabelBase{
|
||||
Label: out.Label.Key,
|
||||
LabelColor: out.Label.Color,
|
||||
LabelScope: out.Label.Scope,
|
||||
Value: value,
|
||||
ValueColor: valueColor,
|
||||
OldValue: oldValue,
|
||||
OldValueColor: oldValueColor,
|
||||
},
|
||||
Type: out.ActivityType,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -61,12 +61,14 @@ func (c *Controller) UnassignLabel(
|
|||
color = &labelValue.Color
|
||||
}
|
||||
payload := &types.PullRequestActivityLabel{
|
||||
Label: label.Key,
|
||||
LabelColor: label.Color,
|
||||
LabelScope: label.Scope,
|
||||
Value: value,
|
||||
ValueColor: color,
|
||||
Type: enum.LabelActivityUnassign,
|
||||
PullRequestActivityLabelBase: types.PullRequestActivityLabelBase{
|
||||
Label: label.Key,
|
||||
LabelColor: label.Color,
|
||||
LabelScope: label.Scope,
|
||||
Value: value,
|
||||
ValueColor: color,
|
||||
},
|
||||
Type: enum.LabelActivityUnassign,
|
||||
}
|
||||
if _, err := c.activityStore.CreateWithPayload(
|
||||
ctx, pullreq, session.Principal.ID, payload, nil); err != nil {
|
||||
|
|
|
@ -204,7 +204,9 @@ func (c *Controller) Create(
|
|||
return nil, fmt.Errorf("failed to prepare labels: %w", err)
|
||||
}
|
||||
|
||||
activitySeq += int64(len(labelAssignInputMap))
|
||||
if len(labelAssignInputMap) > 0 {
|
||||
activitySeq++
|
||||
}
|
||||
|
||||
err = controller.TxOptLock(ctx, c.tx, func(ctx context.Context) error {
|
||||
// Always re-fetch at the start of the transaction because the repo we have is from a cache.
|
||||
|
@ -609,14 +611,37 @@ func (c *Controller) storeLabelAssignActivity(
|
|||
principalID int64,
|
||||
labelAssignOuts []*labelsvc.AssignToPullReqOut,
|
||||
) {
|
||||
for _, out := range labelAssignOuts {
|
||||
payload := activityPayload(out)
|
||||
pr.ActivitySeq++
|
||||
if _, err := c.activityStore.CreateWithPayload(
|
||||
ctx, pr, principalID, payload, nil,
|
||||
); err != nil {
|
||||
log.Ctx(ctx).Err(err).Msg("failed to write label assign pull req activity")
|
||||
if len(labelAssignOuts) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
pr.ActivitySeq++
|
||||
|
||||
payload := &types.PullRequestActivityLabels{
|
||||
Labels: make([]*types.PullRequestActivityLabelBase, len(labelAssignOuts)),
|
||||
Type: enum.LabelActivityAssign,
|
||||
}
|
||||
|
||||
for i, out := range labelAssignOuts {
|
||||
var value *string
|
||||
var valueColor *enum.LabelColor
|
||||
if out.NewLabelValue != nil {
|
||||
value = &out.NewLabelValue.Value
|
||||
valueColor = &out.NewLabelValue.Color
|
||||
}
|
||||
payload.Labels[i] = &types.PullRequestActivityLabelBase{
|
||||
Label: out.Label.Key,
|
||||
LabelColor: out.Label.Color,
|
||||
LabelScope: out.Label.Scope,
|
||||
Value: value,
|
||||
ValueColor: valueColor,
|
||||
}
|
||||
}
|
||||
|
||||
if _, err := c.activityStore.CreateWithPayload(
|
||||
ctx, pr, principalID, payload, nil,
|
||||
); err != nil {
|
||||
log.Ctx(ctx).Err(err).Msg("failed to write label assign pull req activity")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -179,17 +179,29 @@ func (a *PullRequestActivityPayloadBranchRestore) ActivityType() enum.PullReqAct
|
|||
return enum.PullReqActivityTypeBranchRestore
|
||||
}
|
||||
|
||||
type PullRequestActivityLabelBase struct {
|
||||
Label string `json:"label"`
|
||||
LabelColor enum.LabelColor `json:"label_color"`
|
||||
LabelScope int64 `json:"label_scope"`
|
||||
Value *string `json:"value,omitempty"`
|
||||
ValueColor *enum.LabelColor `json:"value_color,omitempty"`
|
||||
OldValue *string `json:"old_value,omitempty"`
|
||||
OldValueColor *enum.LabelColor `json:"old_value_color,omitempty"`
|
||||
}
|
||||
type PullRequestActivityLabel struct {
|
||||
Label string `json:"label"`
|
||||
LabelColor enum.LabelColor `json:"label_color"`
|
||||
LabelScope int64 `json:"label_scope"`
|
||||
Value *string `json:"value,omitempty"`
|
||||
ValueColor *enum.LabelColor `json:"value_color,omitempty"`
|
||||
OldValue *string `json:"old_value,omitempty"`
|
||||
OldValueColor *enum.LabelColor `json:"old_value_color,omitempty"`
|
||||
Type enum.PullReqLabelActivityType `json:"type"`
|
||||
PullRequestActivityLabelBase
|
||||
Type enum.PullReqLabelActivityType `json:"type"`
|
||||
}
|
||||
|
||||
func (a *PullRequestActivityLabel) ActivityType() enum.PullReqActivityType {
|
||||
return enum.PullReqActivityTypeLabelModify
|
||||
}
|
||||
|
||||
type PullRequestActivityLabels struct {
|
||||
Type enum.PullReqLabelActivityType `json:"type"`
|
||||
Labels []*PullRequestActivityLabelBase `json:"labels"`
|
||||
}
|
||||
|
||||
func (a *PullRequestActivityLabels) ActivityType() enum.PullReqActivityType {
|
||||
return enum.PullReqActivityTypeLabelModify
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue