Skip to content

Commit

Permalink
Migrate git-init image off PipelineResourceResult
Browse files Browse the repository at this point in the history
This commit makes introduces the generics of PipelineResourceResult
and TaskrunResult in termination package and migrates the git-init image
off from using PipelineResourceResult.
  • Loading branch information
JeromeJu committed Mar 9, 2023
1 parent 9c4d457 commit e78dd84
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
18 changes: 9 additions & 9 deletions cmd/git-init/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package main

import (
"flag"
"os"

"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
"github.com/tektoncd/pipeline/pkg/git"
Expand Down Expand Up @@ -58,17 +57,18 @@ func main() {
if err != nil {
logger.Fatalf("Error parsing revision %s of git repository: %s", fetchSpec.Revision, err)
}
resourceName := os.Getenv("TEKTON_RESOURCE_NAME")
output := []v1beta1.PipelineResourceResult{
output := []v1beta1.TaskRunResult{
{
Key: "commit",
Value: commit,
ResourceName: resourceName,
Name: "commit",
Value: v1beta1.ParamValue{
StringVal: commit,
},
},
{
Key: "url",
Value: fetchSpec.URL,
ResourceName: resourceName,
Name: "url",
Value: v1beta1.ParamValue{
StringVal: fetchSpec.URL,
},
},
}

Expand Down
8 changes: 6 additions & 2 deletions pkg/termination/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,17 @@ const (
MaxContainerTerminationMessageLength = 1024 * 4
)

type iResult interface {
v1beta1.TaskRunResult | v1beta1.PipelineResourceResult
}

// WriteMessage writes the results to the termination message path.
func WriteMessage(path string, pro []v1beta1.PipelineResourceResult) error {
func WriteMessage[T v1beta1.TaskRunResult | v1beta1.PipelineResourceResult](path string, pro []T) error {
// if the file at path exists, concatenate the new values otherwise create it
// file at path already exists
fileContents, err := os.ReadFile(path)
if err == nil {
var existingEntries []v1beta1.PipelineResourceResult
var existingEntries []T
if err := json.Unmarshal(fileContents, &existingEntries); err == nil {
// append new entries to existing entries
pro = append(existingEntries, pro...)
Expand Down

0 comments on commit e78dd84

Please sign in to comment.