Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions applicationset/generators/pull_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ func (g *PullRequestGenerator) GenerateParams(appSetGenerator *argoprojiov1alpha
"head_short_sha": pull.HeadSHA[:shortSHALength],
"head_short_sha_7": pull.HeadSHA[:shortSHALength7],
"author": pull.Author,
"created_at": pull.CreatedAt.Format(time.RFC3339),
"updated_at": pull.UpdatedAt.Format(time.RFC3339),
}

// PR lables will only be supported for Go Template appsets, since fasttemplate will be deprecated.
Expand Down
35 changes: 35 additions & 0 deletions applicationset/generators/pull_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand All @@ -13,6 +14,12 @@ import (
argoprojiov1alpha1 "github.com/argoproj/argo-cd/v3/pkg/apis/application/v1alpha1"
)

func parseTimeFromString(t string) time.Time {
pt, _ := time.Parse(time.RFC3339, t)

return pt
}

func TestPullRequestGithubGenerateParams(t *testing.T) {
ctx := t.Context()
cases := []struct {
Expand All @@ -35,6 +42,8 @@ func TestPullRequestGithubGenerateParams(t *testing.T) {
TargetBranch: "master",
HeadSHA: "089d92cbf9ff857a39e6feccd32798ca700fb958",
Author: "testName",
CreatedAt: parseTimeFromString("2011-01-26T19:01:12Z"),
UpdatedAt: parseTimeFromString("2011-01-26T19:01:12Z"),
},
},
nil,
Expand All @@ -52,6 +61,8 @@ func TestPullRequestGithubGenerateParams(t *testing.T) {
"head_short_sha": "089d92cb",
"head_short_sha_7": "089d92c",
"author": "testName",
"created_at": "2011-01-26T19:01:12Z",
"updated_at": "2011-01-26T19:01:12Z",
},
},
expectedErr: nil,
Expand All @@ -68,6 +79,8 @@ func TestPullRequestGithubGenerateParams(t *testing.T) {
TargetBranch: "feat/anotherreally+long_pull_request_name_to_test_argo_slugification_and_branch_name_shortening_feature",
HeadSHA: "9b34ff5bd418e57d58891eb0aa0728043ca1e8be",
Author: "testName",
CreatedAt: parseTimeFromString("2011-01-26T19:01:12Z"),
UpdatedAt: parseTimeFromString("2011-01-26T19:01:12Z"),
},
},
nil,
Expand All @@ -85,6 +98,8 @@ func TestPullRequestGithubGenerateParams(t *testing.T) {
"head_short_sha": "9b34ff5b",
"head_short_sha_7": "9b34ff5",
"author": "testName",
"created_at": "2011-01-26T19:01:12Z",
"updated_at": "2011-01-26T19:01:12Z",
},
},
expectedErr: nil,
Expand All @@ -101,6 +116,8 @@ func TestPullRequestGithubGenerateParams(t *testing.T) {
TargetBranch: "master",
HeadSHA: "abcd",
Author: "testName",
CreatedAt: parseTimeFromString("2011-01-26T19:01:12Z"),
UpdatedAt: parseTimeFromString("2011-01-26T19:01:12Z"),
},
},
nil,
Expand All @@ -118,6 +135,8 @@ func TestPullRequestGithubGenerateParams(t *testing.T) {
"head_short_sha": "abcd",
"head_short_sha_7": "abcd",
"author": "testName",
"created_at": "2011-01-26T19:01:12Z",
"updated_at": "2011-01-26T19:01:12Z",
},
},
expectedErr: nil,
Expand All @@ -134,6 +153,8 @@ func TestPullRequestGithubGenerateParams(t *testing.T) {
TargetBranch: "master",
HeadSHA: "abcd",
Author: "testName",
CreatedAt: parseTimeFromString("2011-01-26T19:01:12Z"),
UpdatedAt: parseTimeFromString("2011-01-26T19:01:12Z"),
},
},
nil,
Expand All @@ -157,6 +178,8 @@ func TestPullRequestGithubGenerateParams(t *testing.T) {
"author": "testName",
"values.foo": "bar",
"values.pr_branch": "my_branch",
"created_at": "2011-01-26T19:01:12Z",
"updated_at": "2011-01-26T19:01:12Z",
},
},
expectedErr: nil,
Expand Down Expand Up @@ -209,6 +232,8 @@ func TestPullRequestGithubGenerateParams(t *testing.T) {
HeadSHA: "089d92cbf9ff857a39e6feccd32798ca700fb958",
Labels: []string{"preview"},
Author: "testName",
CreatedAt: parseTimeFromString("2011-01-26T19:01:12Z"),
UpdatedAt: parseTimeFromString("2011-01-26T19:01:12Z"),
},
},
nil,
Expand All @@ -227,6 +252,8 @@ func TestPullRequestGithubGenerateParams(t *testing.T) {
"head_short_sha_7": "089d92c",
"labels": []string{"preview"},
"author": "testName",
"created_at": "2011-01-26T19:01:12Z",
"updated_at": "2011-01-26T19:01:12Z",
},
},
expectedErr: nil,
Expand All @@ -250,6 +277,8 @@ func TestPullRequestGithubGenerateParams(t *testing.T) {
HeadSHA: "089d92cbf9ff857a39e6feccd32798ca700fb958",
Labels: []string{"preview"},
Author: "testName",
CreatedAt: parseTimeFromString("2011-01-26T19:01:12Z"),
UpdatedAt: parseTimeFromString("2011-01-26T19:01:12Z"),
},
},
nil,
Expand All @@ -267,6 +296,8 @@ func TestPullRequestGithubGenerateParams(t *testing.T) {
"head_short_sha": "089d92cb",
"head_short_sha_7": "089d92c",
"author": "testName",
"created_at": "2011-01-26T19:01:12Z",
"updated_at": "2011-01-26T19:01:12Z",
},
},
expectedErr: nil,
Expand All @@ -290,6 +321,8 @@ func TestPullRequestGithubGenerateParams(t *testing.T) {
HeadSHA: "abcd",
Author: "testName",
Labels: []string{"preview", "preview:team1"},
CreatedAt: parseTimeFromString("2011-01-26T19:01:12Z"),
UpdatedAt: parseTimeFromString("2011-01-26T19:01:12Z"),
},
},
nil,
Expand All @@ -312,6 +345,8 @@ func TestPullRequestGithubGenerateParams(t *testing.T) {
"author": "testName",
"labels": []string{"preview", "preview:team1"},
"values": map[string]string{"preview_env": "team1"},
"created_at": "2011-01-26T19:01:12Z",
"updated_at": "2011-01-26T19:01:12Z",
},
},
expectedErr: nil,
Expand Down
6 changes: 5 additions & 1 deletion applicationset/services/pull_request/azure_devops.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,11 @@ func (a *AzureDevOpsService) List(ctx context.Context) ([]*PullRequest, error) {
pr.Repository.Name == nil ||
pr.PullRequestId == nil ||
pr.SourceRefName == nil ||
pr.CreationDate == nil ||
pr.TargetRefName == nil ||
pr.LastMergeSourceCommit == nil ||
pr.LastMergeSourceCommit.CommitId == nil {
pr.LastMergeSourceCommit.CommitId == nil ||
pr.LastMergeSourceCommit.Push.Date == nil {
continue
}

Expand All @@ -114,6 +116,8 @@ func (a *AzureDevOpsService) List(ctx context.Context) ([]*PullRequest, error) {
HeadSHA: *pr.LastMergeSourceCommit.CommitId,
Labels: azureDevOpsLabels,
Author: strings.Split(*pr.CreatedBy.UniqueName, "@")[0], // Get the part before the @ in the email-address
CreatedAt: pr.CreationDate.Time,
UpdatedAt: pr.LastMergeSourceCommit.Push.Date.Time,
})
}
}
Expand Down
17 changes: 17 additions & 0 deletions applicationset/services/pull_request/azure_devops_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package pull_request
import (
"errors"
"testing"
"time"

"github.com/microsoft/azure-devops-go-api/azuredevops/v7"
"github.com/microsoft/azure-devops-go-api/azuredevops/v7/core"
"github.com/microsoft/azure-devops-go-api/azuredevops/v7/git"
"github.com/microsoft/azure-devops-go-api/azuredevops/v7/webapi"
Expand Down Expand Up @@ -35,6 +37,13 @@ func createUniqueNamePtr(x string) *string {
return &x
}

func createDatePtr(x string) *azuredevops.Time {
t, _ := time.Parse(time.RFC3339, x)
return &azuredevops.Time{
Time: t.UTC(),
}
}

func TestListPullRequest(t *testing.T) {
teamProject := "myorg_project"
repoName := "myorg_project_repo"
Expand All @@ -43,6 +52,8 @@ func TestListPullRequest(t *testing.T) {
prHeadSha := "cd4973d9d14a08ffe6b641a89a68891d6aac8056"
ctx := t.Context()
uniqueName := "testName"
createdAt := "2025-12-04T19:01:12Z"
updatedAt := "2025-12-04T19:03:25Z"

pullRequestMock := []git.GitPullRequest{
{
Expand All @@ -52,6 +63,9 @@ func TestListPullRequest(t *testing.T) {
TargetRefName: createStringPtr("refs/heads/main"),
LastMergeSourceCommit: &git.GitCommitRef{
CommitId: createStringPtr(prHeadSha),
Push: &git.GitPushRef{
Date: createDatePtr(updatedAt),
},
},
Labels: &[]core.WebApiTagDefinition{},
Repository: &git.GitRepository{
Expand All @@ -60,6 +74,7 @@ func TestListPullRequest(t *testing.T) {
CreatedBy: &webapi.IdentityRef{
UniqueName: createUniqueNamePtr(uniqueName + "@example.com"),
},
CreationDate: createDatePtr(createdAt),
},
}

Expand Down Expand Up @@ -89,6 +104,8 @@ func TestListPullRequest(t *testing.T) {
assert.Equal(t, "feat(123)", list[0].Title)
assert.Equal(t, int64(prID), list[0].Number)
assert.Equal(t, uniqueName, list[0].Author)
assert.Equal(t, createdAt, list[0].CreatedAt.Format(time.RFC3339))
assert.Equal(t, updatedAt, list[0].UpdatedAt.Format(time.RFC3339))
}

func TestConvertLabes(t *testing.T) {
Expand Down
18 changes: 18 additions & 0 deletions applicationset/services/pull_request/bitbucket_cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"net/url"
"strings"
"time"

"github.com/ktrysmt/go-bitbucket"
)
Expand All @@ -23,6 +24,8 @@ type BitbucketCloudPullRequest struct {
Source BitbucketCloudPullRequestSource `json:"source"`
Author BitbucketCloudPullRequestAuthor `json:"author"`
Destination BitbucketCloudPullRequestDestination `json:"destination"`
CreatedOn string `json:"created_on"`
UpdatedOn string `json:"updated_on"`
}

type BitbucketCloudPullRequestDestination struct {
Expand Down Expand Up @@ -51,6 +54,11 @@ type BitbucketCloudPullRequestAuthor struct {
Nickname string `json:"nickname"`
}

type BitbucketCloudPullRequestTime struct {
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
}

type PullRequestResponse struct {
Page int32 `json:"page"`
Size int32 `json:"size"`
Expand Down Expand Up @@ -155,13 +163,23 @@ func (b *BitbucketCloudService) List(_ context.Context) ([]*PullRequest, error)
}

for _, pull := range pulls {
createdAt, err := time.Parse(time.RFC3339, pull.CreatedOn)
if err != nil {
return nil, fmt.Errorf("error parsing CreatedOn field for PR %s %w", pull.CreatedOn, err)
}
updatedAt, err := time.Parse(time.RFC3339, pull.UpdatedOn)
if err != nil {
return nil, fmt.Errorf("error parsing UpdatedOn field for PR %s %w", pull.UpdatedOn, err)
}
pullRequests = append(pullRequests, &PullRequest{
Number: int64(pull.ID),
Title: pull.Title,
Branch: pull.Source.Branch.Name,
TargetBranch: pull.Destination.Branch.Name,
HeadSHA: pull.Source.Commit.Hash,
Author: pull.Author.Nickname,
CreatedAt: createdAt.UTC(),
UpdatedAt: updatedAt.UTC(),
})
}

Expand Down
Loading
Loading