-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat: webhook payload vars * docs: add new vars to docs * feat: use dashboard uri * docs: apply suggestions from code review Co-authored-by: Julianne Fermi <[email protected]> --------- Co-authored-by: Julianne Fermi <[email protected]>
- Loading branch information
Showing
9 changed files
with
150 additions
and
42 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
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
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 |
---|---|---|
|
@@ -12,4 +12,5 @@ type ProContext struct { | |
OrgID string | ||
Migrate string | ||
ConnectionTimeout int | ||
DashboardURI string | ||
} |
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
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
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,56 @@ | ||
package webhook | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/kubeshop/testkube/internal/config" | ||
"github.com/kubeshop/testkube/pkg/api/v1/testkube" | ||
) | ||
|
||
type TemplateVars struct { | ||
testkube.Event | ||
ExecutionURL string | ||
ExecutionCommand string | ||
ArtifactURL string | ||
ArtifactCommand string | ||
LogsURL string | ||
LogsCommand string | ||
} | ||
|
||
func NewTemplateVars(event testkube.Event, proContext *config.ProContext) TemplateVars { | ||
vars := TemplateVars{ | ||
Event: event, | ||
} | ||
|
||
switch { | ||
case event.TestExecution != nil: | ||
vars.ExecutionCommand = fmt.Sprintf("kubectl testkube get execution %s", event.TestExecution.Id) | ||
vars.ArtifactCommand = fmt.Sprintf("kubectl testkube get artifacts %s", event.TestExecution.Id) | ||
vars.LogsCommand = fmt.Sprintf("kubectl testkube get execution %s --logs-only", event.TestExecution.Id) | ||
case event.TestSuiteExecution != nil: | ||
vars.ExecutionCommand = fmt.Sprintf("kubectl testkube get testsuiteexecution %s", event.TestSuiteExecution.Id) | ||
case event.TestWorkflowExecution != nil: | ||
vars.ExecutionCommand = fmt.Sprintf("kubectl testkube get testworkflowexecution %s", event.TestWorkflowExecution.Id) | ||
vars.ArtifactCommand = fmt.Sprintf("kubectl testkube get artifacts %s", event.TestWorkflowExecution.Id) | ||
vars.LogsCommand = fmt.Sprintf("kubectl testkube get testworkflowexecution %s", event.TestWorkflowExecution.Id) | ||
} | ||
|
||
if proContext == nil || proContext.DashboardURI == "" || proContext.OrgID == "" || proContext.EnvID == "" { | ||
return vars | ||
} | ||
|
||
switch { | ||
case event.TestExecution != nil: | ||
vars.ExecutionURL = fmt.Sprintf("https://%s/organization/%s/environment/%s/dashboard/tests/%s/executions/%s", proContext.DashboardURI, proContext.OrgID, proContext.EnvID, event.TestExecution.TestName, event.TestExecution.Id) | ||
vars.ArtifactURL = fmt.Sprintf("%s/artifacts", vars.ExecutionURL) | ||
vars.LogsURL = fmt.Sprintf("%s/log-output", vars.ExecutionURL) | ||
case event.TestSuiteExecution != nil: | ||
vars.ExecutionURL = fmt.Sprintf("https://%s/organization/%s/environment/%s/dashboard/test-suites/%s/executions/%s", proContext.DashboardURI, proContext.OrgID, proContext.EnvID, event.TestSuiteExecution.TestSuite.Name, event.TestSuiteExecution.Id) | ||
case event.TestWorkflowExecution != nil: | ||
vars.ExecutionURL = fmt.Sprintf("https://%s/organization/%s/environment/%s/dashboard/test-workflows/%s/executions/%s", proContext.DashboardURI, proContext.OrgID, proContext.EnvID, event.TestWorkflowExecution.Workflow.Name, event.TestWorkflowExecution.Id) | ||
vars.ArtifactURL = fmt.Sprintf("%s/artifacts", vars.ExecutionURL) | ||
vars.LogsURL = fmt.Sprintf("%s/log-output", vars.ExecutionURL) | ||
} | ||
|
||
return vars | ||
} |