Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Refactor duplicated code in daemon GC handlers and webhook authorization#423

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
Copilot wants to merge3 commits intodev
base:dev
Choose a base branch
Loading
fromcopilot/refactor-duplicated-code

Conversation

Copy link

CopilotAI commentedOct 30, 2025
edited
Loading

Eliminates ~450 lines of duplicated code across daemon GC runner handlers and webhook authorization checks.

Changes

Daemon GC Handlers (~350 lines eliminated)

  • Extracted common runner formatting logic intopkg/server/handlers/daemons/helpers.go
    • formatRunnerTimestamp(),formatRunnerDuration(),buildRunnerItemBase()
  • Added getter methods toDaemonGc*Runner models implementinggcRunnerBase interface
  • Refactored 12 functions acrossdaemons_gc_{artifact,blob,repository,tags}.go

Before:

// Duplicated in 12 functionsvarstartedAt,endedAt*stringifrunnerObj.StartedAt!=nil {startedAt=ptr.Of(time.Unix(0,int64(time.Millisecond)*ptr.To(runnerObj.StartedAt)).UTC().Format(consts.DefaultTimePattern))}// ... 20+ more lines of identical formatting logic

After:

base:=buildRunnerItemBase(runnerObj)resp=append(resp, types.GcArtifactRunnerItem{ID:base.ID,Status:base.Status,/* ... */})

Webhook Authorization (~100 lines eliminated)

  • CreatedcheckWebhookAuth() helper inpkg/server/handlers/webhooks/helpers.go
  • Consolidated authorization logic from 6 webhook handler files

Before:

// Duplicated in 6 filesifwebhookObj.NamespaceID==nil {if!(user.Role==enums.UserRoleAdmin||user.Role==enums.UserRoleRoot) {returnerrcode.NewHTTPError(c,errcode.HTTPErrCodeUnauthorized,"No permission with this api")    }}else {// 15+ more lines of namespace auth checking}

After:

iferr:=h.checkWebhookAuth(c,user,webhookObj,enums.AuthManage);err!=nil {returnerr}

Impact

  • Future changes to runner formatting or webhook auth require updates in one place
  • Type-safe interface prevents misuse of runner models
  • No behavioral changes
Original prompt

Find and refactor duplicated code


✨ Let Copilot coding agentset things up for you — coding agent works faster and does higher quality work when set up for your repo.

CopilotAIand others added2 commitsOctober 30, 2025 04:11
Co-authored-by: tosone <5346506+tosone@users.noreply.github.com>
Co-authored-by: tosone <5346506+tosone@users.noreply.github.com>
CopilotAI changed the title[WIP] Refactor duplicated code for improved maintainabilityRefactor duplicated code in daemon GC handlers and webhook authorizationOct 30, 2025
CopilotAI requested a review fromtosoneOctober 30, 2025 04:30
Copilot finished work on behalf oftosoneOctober 30, 2025 04:30
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@tosonetosoneAwaiting requested review from tosone

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@tosone

[8]ページ先頭

©2009-2025 Movatter.jp