Skip to content

Commit

Permalink
Refactor JSON and SDK fields (woodpecker-ci#3968)
Browse files Browse the repository at this point in the history
  • Loading branch information
qwerty287 authored and 6543 committed Sep 5, 2024
1 parent 7363b4e commit ec67f74
Show file tree
Hide file tree
Showing 16 changed files with 164 additions and 133 deletions.
43 changes: 17 additions & 26 deletions cmd/server/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4415,8 +4415,7 @@ const docTemplate = `{
"branch": {
"type": "string"
},
"created_at": {
"description": "TODO change JSON field to \"created\" in 3.0",
"created": {
"type": "integer"
},
"creator_id": {
Expand Down Expand Up @@ -4458,15 +4457,13 @@ const docTemplate = `{
"commit": {
"type": "string"
},
"created_at": {
"description": "TODO change JSON field to \"created\" in 3.0",
"created": {
"type": "integer"
},
"event": {
"type": "string"
},
"finished_at": {
"description": "TODO change JSON field to \"finished\" in 3.0",
"finished": {
"type": "integer"
},
"id": {
Expand All @@ -4487,8 +4484,7 @@ const docTemplate = `{
"repo_id": {
"type": "integer"
},
"started_at": {
"description": "TODO change JSON field to \"started\" in 3.0",
"started": {
"type": "integer"
},
"status": {
Expand Down Expand Up @@ -4645,8 +4641,7 @@ const docTemplate = `{
"commit": {
"type": "string"
},
"created_at": {
"description": "TODO change JSON field to \"created\" in 3.0",
"created": {
"type": "integer"
},
"deploy_task": {
Expand All @@ -4664,8 +4659,7 @@ const docTemplate = `{
"event": {
"$ref": "#/definitions/WebhookEvent"
},
"finished_at": {
"description": "TODO change JSON field to \"finished\" in 3.0",
"finished": {
"type": "integer"
},
"forge_url": {
Expand Down Expand Up @@ -4698,8 +4692,7 @@ const docTemplate = `{
"refspec": {
"type": "string"
},
"reviewed_at": {
"description": "TODO change JSON field to \"reviewed\" in 3.0",
"reviewed": {
"type": "integer"
},
"reviewed_by": {
Expand All @@ -4709,8 +4702,7 @@ const docTemplate = `{
"description": "uses reported user for webhooks and name of cron for cron pipelines",
"type": "string"
},
"started_at": {
"description": "TODO change JSON field to \"started\" in 3.0",
"started": {
"type": "integer"
},
"status": {
Expand All @@ -4722,8 +4714,7 @@ const docTemplate = `{
"title": {
"type": "string"
},
"updated_at": {
"description": "TODO change JSON field to \"updated\" in 3.0",
"updated": {
"type": "integer"
},
"variables": {
Expand Down Expand Up @@ -5012,15 +5003,15 @@ const docTemplate = `{
"Step": {
"type": "object",
"properties": {
"end_time": {
"type": "integer"
},
"error": {
"type": "string"
},
"exit_code": {
"type": "integer"
},
"finished": {
"type": "integer"
},
"id": {
"type": "integer"
},
Expand All @@ -5036,7 +5027,7 @@ const docTemplate = `{
"ppid": {
"type": "integer"
},
"start_time": {
"started": {
"type": "integer"
},
"state": {
Expand Down Expand Up @@ -5196,9 +5187,6 @@ const docTemplate = `{
"$ref": "#/definitions/Step"
}
},
"end_time": {
"type": "integer"
},
"environ": {
"type": "object",
"additionalProperties": {
Expand All @@ -5208,6 +5196,9 @@ const docTemplate = `{
"error": {
"type": "string"
},
"finished": {
"type": "integer"
},
"id": {
"type": "integer"
},
Expand All @@ -5223,7 +5214,7 @@ const docTemplate = `{
"platform": {
"type": "string"
},
"start_time": {
"started": {
"type": "integer"
},
"state": {
Expand Down
1 change: 1 addition & 0 deletions docs/docs/91-migrations.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Some versions need some changes to the server configuration or the pipeline conf
- Deprecated `environment` filter, use `when.evaluate`
- Removed `WOODPECKER_WEBHOOK_HOST` in favor of `WOODPECKER_EXPERT_WEBHOOK_HOST`
- Migrated to rfc9421 for webhook signatures
- Renamed `start_time`, `end_time`, `created_at`, `started_at`, `finished_at` and `reviewed_at` JSON fields to `started`, `finished`, `created`, `started`, `finished`, `reviewed`

## 2.0.0

Expand Down
16 changes: 8 additions & 8 deletions server/model/cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ import (
)

type Cron struct {
ID int64 `json:"id" xorm:"pk autoincr 'id'"`
Name string `json:"name" xorm:"name UNIQUE(s) INDEX"`
RepoID int64 `json:"repo_id" xorm:"repo_id UNIQUE(s) INDEX"`
CreatorID int64 `json:"creator_id" xorm:"creator_id INDEX"`
NextExec int64 `json:"next_exec" xorm:"next_exec"`
Schedule string `json:"schedule" xorm:"schedule NOT NULL"` // @weekly, 3min, ...
Created int64 `json:"created_at" xorm:"created NOT NULL DEFAULT 0"` // TODO change JSON field to "created" in 3.0
Branch string `json:"branch" xorm:"branch"`
ID int64 `json:"id" xorm:"pk autoincr 'id'"`
Name string `json:"name" xorm:"name UNIQUE(s) INDEX"`
RepoID int64 `json:"repo_id" xorm:"repo_id UNIQUE(s) INDEX"`
CreatorID int64 `json:"creator_id" xorm:"creator_id INDEX"`
NextExec int64 `json:"next_exec" xorm:"next_exec"`
Schedule string `json:"schedule" xorm:"schedule NOT NULL"` // @weekly, 3min, ...
Created int64 `json:"created" xorm:"created NOT NULL DEFAULT 0"`
Branch string `json:"branch" xorm:"branch"`
} // @name Cron

// TableName returns the database table name for xorm.
Expand Down
6 changes: 3 additions & 3 deletions server/model/feed.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ type Feed struct {
Number int64 `json:"number,omitempty" xorm:"pipeline_number"`
Event string `json:"event,omitempty" xorm:"pipeline_event"`
Status string `json:"status,omitempty" xorm:"pipeline_status"`
Created int64 `json:"created_at,omitempty" xorm:"pipeline_created"` // TODO change JSON field to "created" in 3.0
Started int64 `json:"started_at,omitempty" xorm:"pipeline_started"` // TODO change JSON field to "started" in 3.0
Finished int64 `json:"finished_at,omitempty" xorm:"pipeline_finished"` // TODO change JSON field to "finished" in 3.0
Created int64 `json:"created,omitempty" xorm:"pipeline_created"`
Started int64 `json:"started,omitempty" xorm:"pipeline_started"`
Finished int64 `json:"finished,omitempty" xorm:"pipeline_finished"`
Commit string `json:"commit,omitempty" xorm:"pipeline_commit"`
Branch string `json:"branch,omitempty" xorm:"pipeline_branch"`
Ref string `json:"ref,omitempty" xorm:"pipeline_ref"`
Expand Down
10 changes: 5 additions & 5 deletions server/model/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ type Pipeline struct {
Event WebhookEvent `json:"event" xorm:"event"`
Status StatusValue `json:"status" xorm:"INDEX 'status'"`
Errors []*types.PipelineError `json:"errors" xorm:"json 'errors'"`
Created int64 `json:"created_at" xorm:"'created' NOT NULL DEFAULT 0 created"` // TODO change JSON field to "created" in 3.0
Updated int64 `json:"updated_at" xorm:"'updated' NOT NULL DEFAULT 0 updated"` // TODO change JSON field to "updated" in 3.0
Started int64 `json:"started_at" xorm:"started"` // TODO change JSON field to "started" in 3.0
Finished int64 `json:"finished_at" xorm:"finished"` // TODO change JSON field to "finished" in 3.0
Created int64 `json:"created" xorm:"'created' NOT NULL DEFAULT 0 created"`
Updated int64 `json:"updated" xorm:"'updated' NOT NULL DEFAULT 0 updated"`
Started int64 `json:"started" xorm:"started"`
Finished int64 `json:"finished" xorm:"finished"`
DeployTo string `json:"deploy_to" xorm:"deploy"`
DeployTask string `json:"deploy_task" xorm:"deploy_task"`
Commit string `json:"commit" xorm:"commit"`
Expand All @@ -46,7 +46,7 @@ type Pipeline struct {
Email string `json:"author_email" xorm:"email"`
ForgeURL string `json:"forge_url" xorm:"forge_url"`
Reviewer string `json:"reviewed_by" xorm:"reviewer"`
Reviewed int64 `json:"reviewed_at" xorm:"reviewed"` // TODO change JSON field to "reviewed" in 3.0
Reviewed int64 `json:"reviewed" xorm:"reviewed"`
Workflows []*Workflow `json:"workflows,omitempty" xorm:"-"`
ChangedFiles []string `json:"changed_files,omitempty" xorm:"LONGTEXT 'changed_files'"`
AdditionalVariables map[string]string `json:"variables,omitempty" xorm:"json 'additional_variables'"`
Expand Down
4 changes: 2 additions & 2 deletions server/model/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ type Step struct {
Error string `json:"error,omitempty" xorm:"TEXT 'error'"`
Failure string `json:"-" xorm:"failure"`
ExitCode int `json:"exit_code" xorm:"exit_code"`
Started int64 `json:"start_time,omitempty" xorm:"started"`
Finished int64 `json:"end_time,omitempty" xorm:"stopped"`
Started int64 `json:"started,omitempty" xorm:"started"`
Finished int64 `json:"finished,omitempty" xorm:"finished"`
Type StepType `json:"type,omitempty" xorm:"type"`
} // @name Step

Expand Down
4 changes: 2 additions & 2 deletions server/model/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ type Workflow struct {
Name string `json:"name" xorm:"name"`
State StatusValue `json:"state" xorm:"state"`
Error string `json:"error,omitempty" xorm:"TEXT 'error'"`
Started int64 `json:"start_time,omitempty" xorm:"started"`
Finished int64 `json:"end_time,omitempty" xorm:"stopped"`
Started int64 `json:"started,omitempty" xorm:"started"`
Finished int64 `json:"finished,omitempty" xorm:"finished"`
AgentID int64 `json:"agent_id,omitempty" xorm:"agent_id"`
Platform string `json:"platform,omitempty" xorm:"platform"`
Environ map[string]string `json:"environ,omitempty" xorm:"json 'environ'"`
Expand Down
59 changes: 59 additions & 0 deletions server/store/datastore/migration/034_rename_start_end_time.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright 2024 Woodpecker Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package migration

import (
"fmt"

"src.techknowlogick.com/xormigrate"
"xorm.io/xorm"
)

type stepV033 struct {
Finished int64 `xorm:"stopped"`
}

func (stepV033) TableName() string {
return "steps"
}

type workflowV033 struct {
Finished int64 `xorm:"stopped"`
}

func (workflowV033) TableName() string {
return "workflows"
}

var renameStartEndTime = xormigrate.Migration{
ID: "rename-start-end-time",
MigrateSession: func(sess *xorm.Session) (err error) {
if err := sess.Sync(new(stepV033), new(workflowV033)); err != nil {
return fmt.Errorf("sync models failed: %w", err)
}

// Step
if err := renameColumn(sess, "steps", "stopped", "finished"); err != nil {
return err
}

// Workflow
if err := renameColumn(sess, "workflows", "stopped", "finished"); err != nil {
return err
}

return nil
},
}
1 change: 1 addition & 0 deletions server/store/datastore/migration/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ var migrationTasks = []*xormigrate.Migration{
&unifyColumnsTables,
&alterTableRegistriesFixRequiredFields,
&cronWithoutSec,
&renameStartEndTime,
}

var allBeans = []any{
Expand Down
12 changes: 6 additions & 6 deletions web/src/components/repo/pipeline/PipelineLog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@

<div class="flex flex-row items-center ml-auto gap-x-2">
<IconButton
v-if="step?.end_time !== undefined && hasLogs"
v-if="step?.finished !== undefined && hasLogs"
:is-loading="downloadInProgress"
:title="$t('repo.pipeline.actions.log_download')"
class="!hover:bg-white !hover:bg-opacity-10"
icon="download"
@click="download"
/>
<IconButton
v-if="step?.end_time !== undefined && hasLogs && hasPushPermission"
v-if="step?.finished !== undefined && hasLogs && hasPushPermission"
:title="$t('repo.pipeline.actions.log_delete')"
class="!hover:bg-white !hover:bg-opacity-10"
icon="trash"
@click="deleteLogs"
/>
<IconButton
v-if="step?.end_time === undefined"
v-if="step?.finished === undefined"
:title="
autoScroll ? $t('repo.pipeline.actions.log_auto_scroll_off') : $t('repo.pipeline.actions.log_auto_scroll')
"
Expand Down Expand Up @@ -89,13 +89,13 @@

<div class="m-auto text-xl text-wp-text-alt-100">
<span v-if="step?.state === 'skipped'">{{ $t('repo.pipeline.actions.canceled') }}</span>
<span v-else-if="!step?.start_time">{{ $t('repo.pipeline.step_not_started') }}</span>
<span v-else-if="!step?.started">{{ $t('repo.pipeline.step_not_started') }}</span>
<div v-else-if="!loadedLogs">{{ $t('repo.pipeline.loading') }}</div>
<div v-else-if="log?.length === 0">{{ $t('repo.pipeline.no_logs') }}</div>
</div>

<div
v-if="step?.end_time !== undefined"
v-if="step?.finished !== undefined"
class="flex items-center w-full bg-wp-code-100 text-md text-wp-code-text-alt-100 p-4 font-bold"
>
<PipelineStatusIcon :status="step.state" class="!h-4 !w-4" />
Expand Down Expand Up @@ -350,7 +350,7 @@ watch(stepSlug, async () => {
watch(step, async (newStep, oldStep) => {
if (oldStep?.name === newStep?.name) {
if (oldStep?.end_time !== newStep?.end_time && autoScroll.value) {
if (oldStep?.finished !== newStep?.finished && autoScroll.value) {
scrollDown();
}
Expand Down
6 changes: 3 additions & 3 deletions web/src/components/repo/pipeline/PipelineStepDuration.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ const workflow = toRef(props, 'workflow');
const { durationAsNumber } = useDate();
const durationRaw = computed(() => {
const start = (step.value ? step.value?.start_time : workflow.value?.start_time) || 0;
const end = (step.value ? step.value?.end_time : workflow.value?.end_time) || 0;
const start = (step.value ? step.value?.started : workflow.value?.started) || 0;
const end = (step.value ? step.value?.finished : workflow.value?.finished) || 0;
if (end === 0 && start === 0) {
return undefined;
Expand All @@ -43,5 +43,5 @@ const duration = computed(() => {
return durationAsNumber(durationElapsed.value || 0);
});
const started = computed(() => (step.value ? step.value?.start_time : workflow.value?.start_time) !== undefined);
const started = computed(() => (step.value ? step.value?.started : workflow.value?.started) !== undefined);
</script>
2 changes: 1 addition & 1 deletion web/src/components/repo/pipeline/PipelineStepList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
<PipelineStatusIcon :status="workflow.state" class="!h-4 !w-4" />
<span class="truncate">{{ workflow.name }}</span>
<PipelineStepDuration
v-if="workflow.start_time !== workflow.end_time"
v-if="workflow.started !== workflow.finished"
:workflow="workflow"
class="mr-1 pr-2px"
/>
Expand Down
Loading

0 comments on commit ec67f74

Please sign in to comment.