Skip to content
Merged
6 changes: 3 additions & 3 deletions models/actions/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ func (run *ActionRun) HTMLURL() string {
if run.Repo == nil {
return ""
}
return fmt.Sprintf("%s/actions/runs/%d", run.Repo.HTMLURL(), run.Index)
return fmt.Sprintf("%s/actions/runs/%d", run.Repo.HTMLURL(), run.ID)
}

func (run *ActionRun) Link() string {
if run.Repo == nil {
return ""
}
return fmt.Sprintf("%s/actions/runs/%d", run.Repo.Link(), run.Index)
return fmt.Sprintf("%s/actions/runs/%d", run.Repo.Link(), run.ID)
}

func (run *ActionRun) WorkflowLink() string {
Expand Down Expand Up @@ -299,7 +299,7 @@ func CancelJobs(ctx context.Context, jobs []*ActionRunJob) ([]*ActionRunJob, err
if err := StopTask(ctx, job.TaskID, StatusCancelled); err != nil {
return cancelledJobs, err
}
updatedJob, err := GetRunJobByID(ctx, job.ID)
updatedJob, err := GetRunJobByRunAndID(ctx, job.RunID, job.ID)
if err != nil {
return cancelledJobs, fmt.Errorf("get job: %w", err)
}
Expand Down
20 changes: 16 additions & 4 deletions models/actions/run_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,25 @@ func (job *ActionRunJob) ParseJob() (*jobparser.Job, error) {
return workflowJob, nil
}

func GetRunJobByID(ctx context.Context, id int64) (*ActionRunJob, error) {
func GetRunJobByRepoAndID(ctx context.Context, repoID, jobID int64) (*ActionRunJob, error) {
var job ActionRunJob
has, err := db.GetEngine(ctx).Where("id=?", id).Get(&job)
has, err := db.GetEngine(ctx).Where("id=? AND repo_id=?", jobID, repoID).Get(&job)
if err != nil {
return nil, err
} else if !has {
return nil, fmt.Errorf("run job with id %d: %w", id, util.ErrNotExist)
return nil, fmt.Errorf("run job with id %d: %w", jobID, util.ErrNotExist)
}

return &job, nil
}

func GetRunJobByRunAndID(ctx context.Context, runID, jobID int64) (*ActionRunJob, error) {
var job ActionRunJob
has, err := db.GetEngine(ctx).Where("id=? AND run_id=?", jobID, runID).Get(&job)
if err != nil {
return nil, err
} else if !has {
return nil, fmt.Errorf("run job with id %d: %w", jobID, util.ErrNotExist)
}

return &job, nil
Expand Down Expand Up @@ -168,7 +180,7 @@ func UpdateRunJob(ctx context.Context, job *ActionRunJob, cond builder.Cond, col

if job.RunID == 0 {
var err error
if job, err = GetRunJobByID(ctx, job.ID); err != nil {
if job, err = GetRunJobByRepoAndID(ctx, job.RepoID, job.ID); err != nil {
return 0, err
}
}
Expand Down
4 changes: 3 additions & 1 deletion models/actions/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (task *ActionTask) GetRepoLink() string {

func (task *ActionTask) LoadJob(ctx context.Context) error {
if task.Job == nil {
job, err := GetRunJobByID(ctx, task.JobID)
job, err := GetRunJobByRepoAndID(ctx, task.RepoID, task.JobID)
if err != nil {
return err
}
Expand Down Expand Up @@ -388,6 +388,7 @@ func UpdateTaskByState(ctx context.Context, runnerID int64, state *runnerv1.Task
}
if _, err := UpdateRunJob(ctx, &ActionRunJob{
ID: task.JobID,
RepoID: task.RepoID,
Status: task.Status,
Stopped: task.Stopped,
}, nil); err != nil {
Expand Down Expand Up @@ -449,6 +450,7 @@ func StopTask(ctx context.Context, taskID int64, status Status) error {
task.Stopped = now
if _, err := UpdateRunJob(ctx, &ActionRunJob{
ID: task.JobID,
RepoID: task.RepoID,
Status: task.Status,
Stopped: task.Stopped,
}, nil); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion models/git/commit_status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ func TestCommitStatusesHideActionsURL(t *testing.T) {
statuses := []*git_model.CommitStatus{
{
RepoID: repo.ID,
TargetURL: fmt.Sprintf("%s/jobs/%d", run.Link(), run.Index),
TargetURL: fmt.Sprintf("%s/jobs/%d", run.Link(), run.ID),
},
{
RepoID: repo.ID,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# type ActionRun struct {
# ID int64 `xorm:"pk autoincr"`
# RepoID int64 `xorm:"index"`
# Index int64
# }
-
id: 106
repo_id: 1
index: 7
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# type ActionRunJob struct {
# ID int64 `xorm:"pk autoincr"`
# RunID int64 `xorm:"index"`
# }
-
id: 530
run_id: 106
-
id: 531
run_id: 106
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# type CommitStatus struct {
# ID int64 `xorm:"pk autoincr"`
# RepoID int64 `xorm:"index"`
# TargetURL string
# }
-
id: 10
repo_id: 1
target_url: /testuser/repo1/actions/runs/7/jobs/0
-
id: 11
repo_id: 1
target_url: /testuser/repo1/actions/runs/7/jobs/1
-
id: 12
repo_id: 1
target_url: /otheruser/badrepo/actions/runs/7/jobs/0
-
id: 13
repo_id: 1
target_url: /testuser/repo1/actions/runs/10/jobs/0
-
id: 14
repo_id: 1
target_url: /testuser/repo1/actions/runs/7/jobs/3
-
id: 15
repo_id: 1
target_url: https://ci.example.com/build/123
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# type CommitStatusSummary struct {
# ID int64 `xorm:"pk autoincr"`
# RepoID int64 `xorm:"index"`
# SHA string `xorm:"VARCHAR(64) NOT NULL"`
# State string `xorm:"VARCHAR(7) NOT NULL"`
# TargetURL string
# }
-
id: 20
repo_id: 1
sha: "012345"
state: success
target_url: /testuser/repo1/actions/runs/7/jobs/0
-
id: 21
repo_id: 1
sha: "678901"
state: success
target_url: https://ci.example.com/build/123
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# type Repository struct {
# ID int64 `xorm:"pk autoincr"`
# OwnerName string
# Name string
# }
-
id: 1
owner_name: testuser
name: repo1
1 change: 1 addition & 0 deletions models/migrations/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ func prepareMigrationTasks() []*migration {
newMigration(323, "Add support for actions concurrency", v1_26.AddActionsConcurrency),
newMigration(324, "Fix closed milestone completeness for milestones with no issues", v1_26.FixClosedMilestoneCompleteness),
newMigration(325, "Fix missed repo_id when migrate attachments", v1_26.FixMissedRepoIDWhenMigrateAttachments),
newMigration(326, "Migrate commit status target URL to use run ID and job ID", v1_26.FixCommitStatusTargetURLToUseRunAndJobID),
}
return preparedMigrations
}
Expand Down
Loading