-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
gateway: add api to get commit status deliveries #460
gateway: add api to get commit status deliveries #460
Conversation
@@ -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 { |
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
53be9d2
to
44c8942
Compare
tests/setup_test.go
Outdated
|
||
giteaRepo, project := createProject(ctx, t, giteaClient, gwUser01Client, withVisibility(gwapitypes.VisibilityPrivate)) | ||
|
||
push(t, config, giteaRepo.CloneURL, giteaToken, "commit", false) |
There was a problem hiding this comment.
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.
6a0df88
to
c88acfe
Compare
@@ -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 { |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this log line
tests/setup_test.go
Outdated
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) | ||
} | ||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
c88acfe
to
498621c
Compare
004d0da
to
b84a824
Compare
tests/setup_test.go
Outdated
|
||
giteaRepo, project := createProject(ctx, t, giteaClient, gwUser01Client, withVisibility(gwapitypes.VisibilityPrivate)) | ||
|
||
runNumbers := 5 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
runCount
tests/setup_test.go
Outdated
push(t, fmt.Sprintf(config, i), giteaRepo.CloneURL, giteaToken, "commit", false) | ||
} | ||
|
||
_ = testutil.Wait(150*time.Second, func() (bool, error) { |
There was a problem hiding this comment.
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.
b84a824
to
5001af4
Compare
5001af4
to
e515f66
Compare
@@ -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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
e515f66
to
db0b10d
Compare
This patch adds an api to get commit status deliveries by project ref.