// Copyright 2022 Harness Inc. All rights reserved. // Use of this source code is governed by the Polyform Free Trial License // that can be found in the LICENSE.md file for this repository. package enum // PullReqState defines pull request state. type PullReqState string func (PullReqState) Enum() []interface{} { return toInterfaceSlice(GetAllPullReqStates()) } // PullReqState enumeration. const ( PullReqStateOpen PullReqState = "open" PullReqStateMerged PullReqState = "merged" PullReqStateClosed PullReqState = "closed" PullReqStateRejected PullReqState = "rejected" ) func GetAllPullReqStates() []PullReqState { return []PullReqState{ PullReqStateOpen, PullReqStateMerged, PullReqStateClosed, PullReqStateRejected, } } // PullReqSort defines pull request attribute that can be used for sorting. type PullReqSort string func (PullReqSort) Enum() []interface{} { return toInterfaceSlice(GetAllPullReqSorts()) } // PullReqSort enumeration. const ( PullReqSortNumber = "number" PullReqSortCreated = "created" PullReqSortEdited = "edited" ) func GetAllPullReqSorts() []PullReqSort { return []PullReqSort{ PullReqSortNumber, PullReqSortCreated, PullReqSortEdited, } } var rawPullReqSorts = toSortedStrings(GetAllPullReqActivityTypes()) // ParsePullReqSort parses the PullReqSort. func ParsePullReqSort(s PullReqSort) (PullReqSort, bool) { if existsInSortedSlice(rawPullReqSorts, string(s)) { return s, true } return PullReqSortNumber, false // sorting by the pull request number is default } // PullReqActivityType defines pull request activity message type. // Essentially, the Type determines the structure of the pull request activity's Payload structure. type PullReqActivityType string func (PullReqActivityType) Enum() []interface{} { return toInterfaceSlice(GetAllPullReqActivityTypes()) } // PullReqActivityType enumeration. const ( PullReqActivityTypeComment PullReqActivityType = "comment" PullReqActivityTypeCodeComment PullReqActivityType = "code-comment" PullReqActivityTypeTitleChange PullReqActivityType = "title-change" PullReqActivityTypeReviewSubmit PullReqActivityType = "review-submit" PullReqActivityTypeMerge PullReqActivityType = "merge" ) func GetAllPullReqActivityTypes() []PullReqActivityType { return []PullReqActivityType{ PullReqActivityTypeComment, PullReqActivityTypeCodeComment, PullReqActivityTypeTitleChange, PullReqActivityTypeReviewSubmit, } } var rawPullReqActivityTypes = toSortedStrings(GetAllPullReqActivityTypes()) // ParsePullReqActivityType parses the pull request activity type. func ParsePullReqActivityType(t PullReqActivityType) (PullReqActivityType, bool) { if existsInSortedSlice(rawPullReqActivityTypes, string(t)) { return t, true } return "", false } // PullReqActivityKind defines kind of pull request activity system message. // Kind defines the source of the pull request activity entry: // Whether it's generated by the system, it's a user comment or a part of code review. type PullReqActivityKind string func (PullReqActivityKind) Enum() []interface{} { return toInterfaceSlice(GetAllPullReqActivityKinds()) } // PullReqActivityKind enumeration. const ( PullReqActivityKindSystem PullReqActivityKind = "system" PullReqActivityKindComment PullReqActivityKind = "comment" PullReqActivityKindCodeComment PullReqActivityKind = "code" ) func GetAllPullReqActivityKinds() []PullReqActivityKind { return []PullReqActivityKind{ PullReqActivityKindSystem, PullReqActivityKindComment, PullReqActivityKindCodeComment, } } var rawPullReqActivityKinds = toSortedStrings(GetAllPullReqActivityKinds()) // ParsePullReqActivityKind parses the pull request activity type. func ParsePullReqActivityKind(k PullReqActivityKind) (PullReqActivityKind, bool) { if existsInSortedSlice(rawPullReqActivityKinds, string(k)) { return k, true } return "", false } // PullReqReviewDecision defines state of a pull request review. type PullReqReviewDecision string func (PullReqReviewDecision) Enum() []interface{} { return toInterfaceSlice(GetAllPullReqReviewDecisions()) } // PullReqReviewDecision enumeration. const ( PullReqReviewDecisionPending PullReqReviewDecision = "pending" PullReqReviewDecisionReviewed PullReqReviewDecision = "reviewed" PullReqReviewDecisionApproved PullReqReviewDecision = "approved" PullReqReviewDecisionChangeReq PullReqReviewDecision = "changereq" ) func GetAllPullReqReviewDecisions() []PullReqReviewDecision { return []PullReqReviewDecision{ PullReqReviewDecisionPending, PullReqReviewDecisionReviewed, PullReqReviewDecisionApproved, PullReqReviewDecisionChangeReq, } } var rawPullReqReviewDecisions = toSortedStrings(GetAllPullReqReviewDecisions()) // ParsePullReqReviewDecision parses the pull request review state type. func ParsePullReqReviewDecision(decision PullReqReviewDecision) (PullReqReviewDecision, bool) { if existsInSortedSlice(rawPullReqReviewDecisions, string(decision)) { return decision, true } return "", false } // PullReqReviewerType defines type of a pull request reviewer. type PullReqReviewerType string func (PullReqReviewerType) Enum() []interface{} { return toInterfaceSlice(GetAllPullReqReviewerTypes()) } // PullReqReviewerType enumeration. const ( PullReqReviewerTypeRequested PullReqReviewerType = "requested" PullReqReviewerTypeAssigned PullReqReviewerType = "assigned" PullReqReviewerTypeSelfAssigned PullReqReviewerType = "self_assigned" ) func GetAllPullReqReviewerTypes() []PullReqReviewerType { return []PullReqReviewerType{ PullReqReviewerTypeRequested, PullReqReviewerTypeAssigned, PullReqReviewerTypeSelfAssigned, } } var rawPullReqReviewerTypes = toSortedStrings(GetAllPullReqReviewerTypes()) // ParsePullReqReviewerType parses the pull request reviewer type. func ParsePullReqReviewerType(reviewerType PullReqReviewerType) (PullReqReviewerType, bool) { if existsInSortedSlice(rawPullReqReviewerTypes, string(reviewerType)) { return reviewerType, true } return "", false } // MergeMethod represents the approach to merge commits into base branch. type MergeMethod string func (MergeMethod) Enum() []interface{} { return toInterfaceSlice(GetAllMergeMethods()) } const ( // MergeMethodMerge create merge commit. MergeMethodMerge MergeMethod = "merge" // MergeMethodSquash squash commits into single commit before merging. MergeMethodSquash MergeMethod = "squash" // MergeMethodRebase rebase before merging. MergeMethodRebase MergeMethod = "rebase" ) func GetAllMergeMethods() []MergeMethod { return []MergeMethod{ MergeMethodMerge, MergeMethodSquash, MergeMethodRebase, } } var rawMergeMethods = toSortedStrings(GetAllMergeMethods()) // ParseMergeMethod parses the pull request review state type. func ParseMergeMethod(method MergeMethod) (MergeMethod, bool) { if existsInSortedSlice(rawMergeMethods, string(method)) { return method, true } return "", false }