Skip to content

Commit

Permalink
add log url and env url
Browse files Browse the repository at this point in the history
  • Loading branch information
msiegenthaler committed Mar 1, 2021
1 parent c340fb1 commit cde1a4f
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 24 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ Create a new Deployment, or update a given Deployment with a new DeploymentStatu

* `description`: *Optional.* The description of the deployment.

* `environment_url`: *Optional.* URL of the deployment

* `auto_merge`: *Optional.* Whether to auto-merge the repository's default branch into the deployment ref. Defaults to true.

* `payload`: *Optional.* Additional data about the deployment.
Expand All @@ -103,6 +105,8 @@ NB: If there are duplicate keys in data from `payload` and `payload_path`, then

* `task`: *Optional.* The name of the task for the deployment.

The log url is automatically set to the url of the concourse build.

##### Reading values from files

All of the above parameters can be used to pass the name of a file to read the applicable value
Expand Down
30 changes: 30 additions & 0 deletions concourse_metadata.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package resource

import (
"fmt"
"os"
)

type ConcourseMetadata struct {
ATCExternalURL string `json:"atc_external_url"`
BuildID string `json:"build_id"`
BuildJobName string `json:"build_job_name"`
BuildName string `json:"build_name"`
BuildPipelineName string `json:"build_pipeline_name"`
BuildTeamName string `json:"build_team_name"`
BuildURL string `json:"build_url"`
}

func GetConcourseMetadata() ConcourseMetadata {
buildURL := fmt.Sprintf("%v/teams/%v/pipelines/%v/jobs/%v/builds/%v",
os.Getenv("ATC_EXTERNAL_URL"), os.Getenv("BUILD_TEAM_NAME"), os.Getenv("BUILD_PIPELINE_NAME"), os.Getenv("BUILD_JOB_NAME"), os.Getenv("BUILD_NAME"))
return ConcourseMetadata{
ATCExternalURL: os.Getenv("ATC_EXTERNAL_URL"),
BuildID: os.Getenv("BUILD_ID"),
BuildJobName: os.Getenv("BUILD_JOB_NAME"),
BuildName: os.Getenv("BUILD_NAME"),
BuildPipelineName: os.Getenv("BUILD_PIPELINE_NAME"),
BuildTeamName: os.Getenv("BUILD_TEAM_NAME"),
BuildURL: buildURL,
}
}
12 changes: 1 addition & 11 deletions deployment_out_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"io"
"io/ioutil"
"os"
"strconv"
"strings"

Expand Down Expand Up @@ -35,16 +34,7 @@ func (c *DeploymentOutCommand) Run(sourceDir string, request OutRequest) (OutRes
RequiredContexts: &[]string{},
}

concoursePayload := map[string]interface{}{
"build_id": os.Getenv("BUILD_ID"),
"build_name": os.Getenv("BUILD_NAME"),
"build_job_name": os.Getenv("BUILD_JOB_NAME"),
"build_pipeline_name": os.Getenv("BUILD_PIPELINE_NAME"),
"build_team_name": os.Getenv("BUILD_TEAM_NAME"),
"build_url": fmt.Sprintf("%v/teams/%v/pipelines/%v/jobs/%v/builds/%v",
os.Getenv("ATC_EXTERNAL_URL"), os.Getenv("BUILD_TEAM_NAME"), os.Getenv("BUILD_PIPELINE_NAME"), os.Getenv("BUILD_JOB_NAME"), os.Getenv("BUILD_NAME")),
"atc_external_url": os.Getenv("ATC_EXTERNAL_URL"),
}
concoursePayload := GetConcourseMetadata()

if request.Params.Payload != nil && *request.Params.Payload != nil {
payload := *request.Params.Payload
Expand Down
7 changes: 5 additions & 2 deletions out_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,12 @@ func (c *OutCommand) Run(sourceDir string, request OutRequest) (OutResponse, err
return OutResponse{}, err
}

concourseMetadata := GetConcourseMetadata()
newStatus := &github.DeploymentStatusRequest{
State: request.Params.State,
Description: request.Params.Description,
State: request.Params.State,
Description: request.Params.Description,
LogURL: &concourseMetadata.BuildURL,
EnvironmentURL: request.Params.EnvironmentURL,
}

if request.Params.LogURL != nil && *request.Params.LogURL != "" {
Expand Down
23 changes: 12 additions & 11 deletions resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,18 @@ type OutResponse struct {
}

type OutParams struct {
Type *string `json:"type"`
ID *string
Ref *string
Environment *string
Task *string
State *string
Description *string
AutoMerge *bool
Payload *map[string]interface{}
PayloadPath *string `json:"payload_path"`
LogURL *string
Type *string `json:"type"`
ID *string
Ref *string
Environment *string
Task *string
State *string
Description *string
AutoMerge *bool
Payload *map[string]interface{}
PayloadPath *string `json:"payload_path"`
LogURL *string
EnvironmentURL *string `json:"environment_url,omitempty"`

RawID json.RawMessage `json:"id"`
RawState json.RawMessage `json:"state"`
Expand Down

0 comments on commit cde1a4f

Please sign in to comment.