Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gateway: add api to get commit status deliveries #460

Merged
merged 2 commits into from
Dec 14, 2023

Conversation

alessandro-sorint
Copy link
Contributor

This patch adds an api to get commit status deliveries by project ref.

@@ -504,15 +504,15 @@ func TestCommitStatusDelivery(t *testing.T) {
})
}

func createCommitStatus(t *testing.T, ctx context.Context, ns *NotificationService, n int) *types.CommitStatus {
func createCommitStatus(t *testing.T, ctx context.Context, ns *NotificationService, n int, projectID string) *types.CommitStatus {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename n to something more meaningful.

t.Fatalf("unexpected HasMore false")
}
if len(res.CommitStatusDeliveries) != 10 {
t.Fatalf("unexpected 10 commit status deliveries, got %d", len(res.CommitStatusDeliveries))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unexpected or expected? Probably wrong also in the code you copied.

t.Fatalf("unexpected HasMore true")
}
if len(res.CommitStatusDeliveries) != 10 {
t.Fatalf("unexpected 10 commit status deliveries, got %d", len(res.CommitStatusDeliveries))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unexpected or expected? Probably wrong also in the code you copied.

t.Fatalf("unexpected HasMore false")
}
if len(res.CommitStatusDeliveries) != 5 {
t.Fatalf("unexpected 5 commit status deliveries, got %d", len(res.CommitStatusDeliveries))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unexpected or expected? Probably wrong also in the code you copied.


t.Logf("starting ns")

time.Sleep(1 * time.Second)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid time.Sleep. Probably wrong also in the code you copied from.


giteaRepo, project := createProject(ctx, t, giteaClient, gwUser01Client, withVisibility(gwapitypes.VisibilityPrivate))

push(t, config, giteaRepo.CloneURL, giteaToken, "commit", false)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since looks like you get only two commit statuses, why don't you just create more runs? In this way you can check the continuation cursor by iterating more than one time etc... like done for other tests.

@alessandro-sorint alessandro-sorint force-pushed the api-commitstatusdeliveries branch 2 times, most recently from 6a0df88 to c88acfe Compare December 13, 2023 08:16
@@ -496,16 +496,16 @@ func TestCommitStatusDelivery(t *testing.T) {
})
}

func createCommitStatus(t *testing.T, ctx context.Context, ns *NotificationService, n int) *types.CommitStatus {
func createCommitStatus(t *testing.T, ctx context.Context, ns *NotificationService, index int, projectID string) *types.CommitStatus {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why "index" ? it's used for RunCounter and for other unrelated things. Which is the primary use of it? "runCounter"? The other entries (commitSHA, Context etc...) are based on runCounter? If they are meaningless for the tests then document that their value is just a dumb value.


ns := setupNotificationService(ctx, t, log, dir)

t.Logf("starting ns")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this log line

Comment on lines 7280 to 7318
runNumbers := 5

var startRunNumber uint64
for i := 0; i < runNumbers; i++ {
_ = testutil.Wait(30*time.Second, func() (bool, error) {
runs, _, err := gwUser01Client.GetProjectRuns(ctx, project.ID, nil, nil, startRunNumber, 0, true)
if err != nil {
return false, nil
}

if len(runs) == 0 {
return false, nil
}
if runs[0].Phase != rstypes.RunPhaseFinished {
return false, nil
}

return true, nil
})

runs, _, err := gwUser01Client.GetProjectRuns(ctx, project.ID, nil, nil, startRunNumber, 0, true)
if err != nil {
t.Fatalf("unexpected err: %v", err)
}
if len(runs) == 0 {
t.Fatalf("expected 1 run got: %d", len(runs))
}
if runs[0].Phase != rstypes.RunPhaseFinished {
t.Fatalf("expected run phase %q, got %q", rstypes.RunPhaseFinished, runs[0].Phase)
}
if runs[0].Result != rstypes.RunResultSuccess {
t.Fatalf("expected run result %q, got %q", rstypes.RunResultSuccess, runs[0].Result)
}

startRunNumber = runs[0].Number - 1

if i == runNumbers-1 {
break
}

if _, err = gwUser01Client.ProjectCreateRun(ctx, project.ID, &gwapitypes.ProjectCreateRunRequest{Branch: "master"}); err != nil {
t.Fatalf("unexpected err: %v", err)
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't you just call 'push' n times and check that all the runs are finished/successfull instead of 1 time + all of this code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did the change but it fails with setuperror, I have seen it happen because something is wrong with gitea when the runservice get the conf file.. it can be because of too many calls to gitea during the run creation(?). This is why I did it by a for cicle before. I could add a time sleep after evry ProjectCreateRun if it works?


giteaRepo, project := createProject(ctx, t, giteaClient, gwUser01Client, withVisibility(gwapitypes.VisibilityPrivate))

runNumbers := 5
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

runCount

push(t, fmt.Sprintf(config, i), giteaRepo.CloneURL, giteaToken, "commit", false)
}

_ = testutil.Wait(150*time.Second, func() (bool, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

150 seconds is quite a lot.

@@ -214,11 +226,8 @@ func (d *DB) GetLastRunEventSequence(tx *sql.Tx) (*types.LastRunEventSequence, e
return out, errors.WithStack(err)
}

func (d *DB) GetCommitStatusDeliveriesAfterSequence(tx *sql.Tx, afterSequence uint64, deliveryStatus types.DeliveryStatus, limit int) ([]*types.CommitStatusDelivery, error) {
func (d *DB) GetProjectCommitStatusDeliveriesAfterSequence(tx *sql.Tx, afterSequence uint64, limit int) ([]*types.CommitStatusDelivery, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GetProject... is wrong since there's no filter by project. Probably also the function you copied has the same issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the other function with the same issue is GetProjectRunWebhookDeliveriesAfterSequence, should I change in this PR with GetRunWebhookDeliveriesAfterSequence or I must open a new PR?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please open a new PR with a clear/detailed commit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

opened PR #467 to fix

add an api to get commit status deliveries by project id.
add an api to get commit status deliveries by project ref.
@sgotti sgotti merged commit 96ec249 into agola-io:master Dec 14, 2023
1 check was pending
@alessandro-sorint alessandro-sorint deleted the api-commitstatusdeliveries branch December 14, 2023 16:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants