Skip to content

Commit

Permalink
chore: increase the retry times
Browse files Browse the repository at this point in the history
  • Loading branch information
LinuxSuRen committed Mar 11, 2024
1 parent 5e9c409 commit 1a1adaf
Show file tree
Hide file tree
Showing 7 changed files with 399 additions and 170 deletions.
38 changes: 32 additions & 6 deletions cmd/argoworkflow/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
/*
MIT License
Copyright (c) 2023-2024 Rick
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

package main

import (
Expand Down Expand Up @@ -178,12 +202,14 @@ func (e *DefaultPluginExecutor) Execute(args executor.ExecuteTemplateArgs, wf *w
}

fmt.Println("send status", repo)
wait.PollImmediate(time.Second, time.Second*10, func() (bool, error) {
err := pkg.CreateStatus(ctx, repo)
return err == nil, nil
})

fmt.Println("send status success")
if err = wait.PollImmediate(time.Second*2, time.Second*20, func() (bool, error) {
return pkg.CreateStatus(ctx, repo) == nil, nil
}); err == nil {
fmt.Println("send status success", repo)
} else {
fmt.Printf("failed to send the status to %v: %v\n", repo, err)
return
}

if err == nil && opt.Option.CreateComment {
fmt.Println("start to create comment")
Expand Down
2 changes: 2 additions & 0 deletions cmd/argoworkflow/template/comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package template

// CommentTemplate is the default comment template
const CommentTemplate = `
<!-- Generated by https://github.com/LinuxSuRen/gogit -->
[{{.Spec.WorkflowTemplateRef.Name}}]({{get .Annotations "workflow.templatelink"}}) is {{.Status.Phase}}. It started from {{date "01-02 15:04" .Status.StartedAt.Time}}, and took {{duration .Status.FinishedAt .Status.StartedAt}}. Please check log output from [here]({{get .Annotations "workflow.link"}}).
| Stage | Status | Duration |
Expand All @@ -12,6 +13,7 @@ const CommentTemplate = `
`

const OutputsTemplate = `
<!-- Generated by https://github.com/LinuxSuRen/gogit -->
Please feel free to check the following outputs:
| Output |
Expand Down
455 changes: 298 additions & 157 deletions go.work.sum

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions pkg/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func NewMaker(ctx context.Context, repoInfo RepoInformation) (maker *StatusMaker
return
}

repo := repoInfo.getRepoPath()
repo := repoInfo.GetRepoPath()

Check warning on line 37 in pkg/git.go

View check run for this annotation

Codecov / codecov/patch

pkg/git.go#L37

Added line #L37 was not covered by tests
maker = NewStatusMaker(repo, repoInfo.Token)
maker.WithTarget(repoInfo.Target).WithPR(repoInfo.PrNumber).
WithServer(repoInfo.Server).
Expand Down Expand Up @@ -158,8 +158,8 @@ func (s *StatusMaker) CreateComment(ctx context.Context, message, endMarker stri
}

func getCommentIDs(comments []*scm.Comment, endMarker string) (commentIDs []int) {
for _, comment := range comments {
// comment := comments[i]
for i := range comments {
comment := comments[i]
if strings.HasSuffix(comment.Body, endMarker) {
commentIDs = append(commentIDs, comment.ID)
}
Expand Down
5 changes: 4 additions & 1 deletion pkg/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,11 @@ func TestGetCommentIDs(t *testing.T) {
}, {
Body: "other",
ID: 4,
}, {
Body: "good - end",
ID: 5,
}},
expect: []int{2, 3},
expect: []int{2, 3, 5},
}}
for _, tt := range tests {
assert.Equal(t, tt.expect, getCommentIDs(tt.comments, "end"))
Expand Down
32 changes: 31 additions & 1 deletion pkg/type.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
/*
MIT License
Copyright (c) 2023-2024 Rick
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

package pkg

import "fmt"
Expand All @@ -17,6 +41,12 @@ type RepoInformation struct {
Description string
}

func (r RepoInformation) getRepoPath() string {
// String returns the human-readable string
func (r RepoInformation) String() string {
return r.GetRepoPath()
}

// GetRepoPath returns the repository path
func (r RepoInformation) GetRepoPath() string {
return fmt.Sprintf("%s/%s", r.Owner, r.Repo)
}
31 changes: 29 additions & 2 deletions pkg/type_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
/*
MIT License
Copyright (c) 2023-2024 Rick
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

package pkg

import "testing"
Expand Down Expand Up @@ -25,8 +49,11 @@ func TestRepoInformation_getRepoPath(t *testing.T) {
Owner: tt.fields.Owner,
Repo: tt.fields.Repo,
}
if got := r.getRepoPath(); got != tt.want {
t.Errorf("getRepoPath() = %v, want %v", got, tt.want)
if got := r.GetRepoPath(); got != tt.want {
t.Errorf("GetRepoPath() = %v, want %v", got, tt.want)
}
if got := r.String(); got != tt.want {
t.Errorf("String() = %v, want %v", got, tt.want)
}
})
}
Expand Down

0 comments on commit 1a1adaf

Please sign in to comment.