-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add GetApprovalDetails function * Add ApproveOrRejectApprovals function for CG
- Loading branch information
Showing
6 changed files
with
215 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
package cd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/harness/harness-go-sdk/harness/cd/graphql" | ||
) | ||
|
||
// Helper type for accessing all application related crud methods | ||
type ApprovalClient struct { | ||
ApiClient *ApiClient | ||
} | ||
|
||
// CRUD | ||
func (ac *ApprovalClient) GetApprovalDetails(applicationId string, executionId string) (*graphql.ApprovalDetailsPayload, error) { | ||
query := &GraphQLQuery{ | ||
Query: fmt.Sprintf(`query($applicationId: String!, $executionId: String!) { | ||
approvalDetails(applicationId: $applicationId, executionId: $executionId) { | ||
approvalDetails { | ||
%s | ||
} | ||
} | ||
}`, approvalDetailsFields), | ||
Variables: map[string]interface{}{ | ||
"applicationId": applicationId, | ||
"executionId": executionId, | ||
}, | ||
} | ||
|
||
res := struct { | ||
ApprovalDetails graphql.ApprovalDetailsPayload | ||
}{} | ||
ac.ApiClient.ExecuteGraphQLQuery(query, &res) | ||
|
||
return &res.ApprovalDetails, nil | ||
} | ||
|
||
func (ac *ApprovalClient) ApproveOrRejectApprovals(input *graphql.ApproveOrRejectApprovalsInput) (*graphql.ApproveOrRejectApprovalsInputPayload, error) { | ||
|
||
query := &GraphQLQuery{ | ||
Query: `mutation approveOrRejectApprovals ($approvalInput: ApproveOrRejectApprovalsInput!) { | ||
approveOrRejectApprovals(input: $approvalInput) | ||
{ | ||
success | ||
clientMutationId | ||
} | ||
}`, | ||
Variables: map[string]interface{}{ | ||
"approvalInput": &input, | ||
}, | ||
} | ||
|
||
res := &struct { | ||
ApproveOrRejectApprovalsInputPayload *graphql.ApproveOrRejectApprovalsInputPayload | ||
}{} | ||
err := ac.ApiClient.ExecuteGraphQLQuery(query, &res) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return res.ApproveOrRejectApprovalsInputPayload, nil | ||
} | ||
|
||
var approvalDetailsFields = ` | ||
approvalId | ||
approvalType | ||
stepName | ||
stageName | ||
startedAt | ||
triggeredBy { | ||
name | ||
} | ||
willExpireAt | ||
... on UserGroupApprovalDetails { | ||
approvers | ||
approvalId | ||
approvalType | ||
stepName | ||
stageName | ||
startedAt | ||
executionId | ||
triggeredBy { | ||
name | ||
} | ||
willExpireAt | ||
variables { | ||
name | ||
value | ||
} | ||
} | ||
... on ShellScriptDetails { | ||
approvalId | ||
approvalType | ||
retryInterval | ||
stageName | ||
stepName | ||
startedAt | ||
triggeredBy { | ||
name | ||
} | ||
willExpireAt | ||
} | ||
... on SNOWApprovalDetails { | ||
approvalCondition | ||
approvalId | ||
approvalType | ||
currentStatus | ||
rejectionCondition | ||
stageName | ||
startedAt | ||
stepName | ||
ticketType | ||
ticketUrl | ||
triggeredBy { | ||
name | ||
} | ||
willExpireAt | ||
} | ||
... on JiraApprovalDetails { | ||
approvalCondition | ||
approvalId | ||
approvalType | ||
currentStatus | ||
issueKey | ||
issueUrl | ||
rejectionCondition | ||
stepName | ||
stageName | ||
startedAt | ||
triggeredBy { | ||
name | ||
} | ||
willExpireAt | ||
} | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package cd | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestApprovalDetails(t *testing.T) { | ||
c := getClient() | ||
approval, err := c.ApprovalClient.GetApprovalDetails("q_nsFwL5TUq4Jsq00vNGRQ-gf39sw", "ntUxF8b_SRuSWLckvPkODw") | ||
require.NoError(t, err) | ||
require.NotNil(t, approval) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package graphql | ||
|
||
type ApprovalActionType string | ||
|
||
var ApprovalActionTypes = struct { | ||
Approve ApprovalActionType | ||
Reject ApprovalActionType | ||
}{ | ||
Approve: "APPROVE", | ||
Reject: "REJECT", | ||
} | ||
|
||
var ApprovalActionTypeList = []string{ | ||
ApprovalActionTypes.Approve.String(), | ||
ApprovalActionTypes.Reject.String(), | ||
} | ||
|
||
func (d ApprovalActionType) String() string { | ||
return string(d) | ||
} |
11 changes: 11 additions & 0 deletions
11
harness/cd/graphql/model_approve_or_reject_approvals_input.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package graphql | ||
|
||
type ApproveOrRejectApprovalsInput struct { | ||
Action ApprovalActionType `json:"action,omitempty"` | ||
ApplicationId string `json:"applicationId,omitempty"` | ||
ApprovalId string `json:"approvalId,omitempty"` | ||
ClientMutationId string `json:"clientMutationId,omitempty"` | ||
Comments string `json:"comments,omitempty"` | ||
ExecutionId string `json:"executionId,omitempty"` | ||
VariableInputs []*ApprovalVariable `json:"variableInputs,omitempty"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters