|
17 | 17 | package gitlab
|
18 | 18 |
|
19 | 19 | import (
|
| 20 | + "encoding/json" |
| 21 | + "fmt" |
| 22 | + "strconv" |
20 | 23 | "time"
|
21 | 24 | )
|
22 | 25 |
|
@@ -512,41 +515,39 @@ type MergeEvent struct {
|
512 | 515 | Visibility VisibilityValue `json:"visibility"`
|
513 | 516 | } `json:"project"`
|
514 | 517 | ObjectAttributes struct {
|
515 |
| - ID int `json:"id"` |
516 |
| - TargetBranch string `json:"target_branch"` |
517 |
| - SourceBranch string `json:"source_branch"` |
518 |
| - SourceProjectID int `json:"source_project_id"` |
519 |
| - AuthorID int `json:"author_id"` |
520 |
| - AssigneeID int `json:"assignee_id"` |
521 |
| - Title string `json:"title"` |
522 |
| - CreatedAt string `json:"created_at"` // Should be *time.Time (see Gitlab issue #21468) |
523 |
| - UpdatedAt string `json:"updated_at"` // Should be *time.Time (see Gitlab issue #21468) |
524 |
| - StCommits []*Commit `json:"st_commits"` |
525 |
| - StDiffs []*Diff `json:"st_diffs"` |
526 |
| - MilestoneID int `json:"milestone_id"` |
527 |
| - State string `json:"state"` |
528 |
| - MergeStatus string `json:"merge_status"` |
529 |
| - TargetProjectID int `json:"target_project_id"` |
530 |
| - IID int `json:"iid"` |
531 |
| - Description string `json:"description"` |
532 |
| - Position int `json:"position"` |
533 |
| - LockedAt string `json:"locked_at"` |
534 |
| - UpdatedByID int `json:"updated_by_id"` |
535 |
| - MergeError string `json:"merge_error"` |
536 |
| - MergeParams struct { |
537 |
| - ForceRemoveSourceBranch string `json:"force_remove_source_branch"` |
538 |
| - } `json:"merge_params"` |
539 |
| - MergeWhenBuildSucceeds bool `json:"merge_when_build_succeeds"` |
540 |
| - MergeUserID int `json:"merge_user_id"` |
541 |
| - MergeCommitSHA string `json:"merge_commit_sha"` |
542 |
| - DeletedAt string `json:"deleted_at"` |
543 |
| - ApprovalsBeforeMerge string `json:"approvals_before_merge"` |
544 |
| - RebaseCommitSHA string `json:"rebase_commit_sha"` |
545 |
| - InProgressMergeCommitSHA string `json:"in_progress_merge_commit_sha"` |
546 |
| - LockVersion int `json:"lock_version"` |
547 |
| - TimeEstimate int `json:"time_estimate"` |
548 |
| - Source *Repository `json:"source"` |
549 |
| - Target *Repository `json:"target"` |
| 518 | + ID int `json:"id"` |
| 519 | + TargetBranch string `json:"target_branch"` |
| 520 | + SourceBranch string `json:"source_branch"` |
| 521 | + SourceProjectID int `json:"source_project_id"` |
| 522 | + AuthorID int `json:"author_id"` |
| 523 | + AssigneeID int `json:"assignee_id"` |
| 524 | + Title string `json:"title"` |
| 525 | + CreatedAt string `json:"created_at"` // Should be *time.Time (see Gitlab issue #21468) |
| 526 | + UpdatedAt string `json:"updated_at"` // Should be *time.Time (see Gitlab issue #21468) |
| 527 | + StCommits []*Commit `json:"st_commits"` |
| 528 | + StDiffs []*Diff `json:"st_diffs"` |
| 529 | + MilestoneID int `json:"milestone_id"` |
| 530 | + State string `json:"state"` |
| 531 | + MergeStatus string `json:"merge_status"` |
| 532 | + TargetProjectID int `json:"target_project_id"` |
| 533 | + IID int `json:"iid"` |
| 534 | + Description string `json:"description"` |
| 535 | + Position int `json:"position"` |
| 536 | + LockedAt string `json:"locked_at"` |
| 537 | + UpdatedByID int `json:"updated_by_id"` |
| 538 | + MergeError string `json:"merge_error"` |
| 539 | + MergeParams *MergeParams `json:"merge_params"` |
| 540 | + MergeWhenBuildSucceeds bool `json:"merge_when_build_succeeds"` |
| 541 | + MergeUserID int `json:"merge_user_id"` |
| 542 | + MergeCommitSHA string `json:"merge_commit_sha"` |
| 543 | + DeletedAt string `json:"deleted_at"` |
| 544 | + ApprovalsBeforeMerge string `json:"approvals_before_merge"` |
| 545 | + RebaseCommitSHA string `json:"rebase_commit_sha"` |
| 546 | + InProgressMergeCommitSHA string `json:"in_progress_merge_commit_sha"` |
| 547 | + LockVersion int `json:"lock_version"` |
| 548 | + TimeEstimate int `json:"time_estimate"` |
| 549 | + Source *Repository `json:"source"` |
| 550 | + Target *Repository `json:"target"` |
550 | 551 | LastCommit struct {
|
551 | 552 | ID string `json:"id"`
|
552 | 553 | Message string `json:"message"`
|
@@ -594,6 +595,45 @@ type MergeEvent struct {
|
594 | 595 | } `json:"changes"`
|
595 | 596 | }
|
596 | 597 |
|
| 598 | +// MergeParams represents the merge params. |
| 599 | +type MergeParams struct { |
| 600 | + ForceRemoveSourceBranch bool `json:"force_remove_source_branch"` |
| 601 | +} |
| 602 | + |
| 603 | +// UnmarshalJSON decodes the merge parameters |
| 604 | +// |
| 605 | +// This allows support of ForceRemoveSourceBranch for both type bool (>11.9) and string (<11.9) |
| 606 | +func (p *MergeParams) UnmarshalJSON(b []byte) error { |
| 607 | + type Alias MergeParams |
| 608 | + raw := struct { |
| 609 | + *Alias |
| 610 | + ForceRemoveSourceBranch interface{} `json:"force_remove_source_branch"` |
| 611 | + }{ |
| 612 | + Alias: (*Alias)(p), |
| 613 | + } |
| 614 | + |
| 615 | + err := json.Unmarshal(b, &raw) |
| 616 | + if err != nil { |
| 617 | + return err |
| 618 | + } |
| 619 | + |
| 620 | + switch v := raw.ForceRemoveSourceBranch.(type) { |
| 621 | + case nil: |
| 622 | + // No action needed. |
| 623 | + case bool: |
| 624 | + p.ForceRemoveSourceBranch = v |
| 625 | + case string: |
| 626 | + p.ForceRemoveSourceBranch, err = strconv.ParseBool(v) |
| 627 | + if err != nil { |
| 628 | + return err |
| 629 | + } |
| 630 | + default: |
| 631 | + return fmt.Errorf("failed to unmarshal ForceRemoveSourceBranch of type: %T", v) |
| 632 | + } |
| 633 | + |
| 634 | + return nil |
| 635 | +} |
| 636 | + |
597 | 637 | // WikiPageEvent represents a wiki page event.
|
598 | 638 | //
|
599 | 639 | // GitLab API docs:
|
|
0 commit comments