mirror of
https://github.com/browseros-ai/BrowserOS.git
synced 2026-05-19 11:31:03 +00:00
* fix: make patch list registry-only * feat: add patch command progress logs * fix: address review feedback for PR #921
58 lines
1.7 KiB
Go
58 lines
1.7 KiB
Go
package engine
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/browseros-ai/BrowserOS/packages/browseros/tools/patch/internal/git"
|
|
"github.com/browseros-ai/BrowserOS/packages/browseros/tools/patch/internal/repo"
|
|
)
|
|
|
|
type PublishResult struct {
|
|
Remote string `json:"remote"`
|
|
Branch string `json:"branch"`
|
|
Message string `json:"message"`
|
|
}
|
|
|
|
type PublishOptions struct {
|
|
Repo *repo.Info
|
|
Remote string
|
|
Message string
|
|
Progress Progress
|
|
}
|
|
|
|
// Publish commits chromium_patches changes and pushes them to the selected remote.
|
|
func Publish(ctx context.Context, opts PublishOptions) (*PublishResult, error) {
|
|
if opts.Remote == "" {
|
|
opts.Remote = "origin"
|
|
}
|
|
if opts.Message == "" {
|
|
opts.Message = "chore: update chromium patches"
|
|
}
|
|
reportProgress(opts.Progress, "Checking chromium_patches changes")
|
|
dirty, err := git.IsDirtyPaths(ctx, opts.Repo.Root, []string{"chromium_patches"})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if !dirty {
|
|
return nil, fmt.Errorf("nothing to publish: chromium_patches has no uncommitted changes")
|
|
}
|
|
reportProgress(opts.Progress, "Staging chromium_patches")
|
|
if err := git.AddPaths(ctx, opts.Repo.Root, []string{"chromium_patches"}); err != nil {
|
|
return nil, err
|
|
}
|
|
reportProgress(opts.Progress, "Committing chromium_patches")
|
|
if err := git.Commit(ctx, opts.Repo.Root, opts.Message); err != nil {
|
|
return nil, err
|
|
}
|
|
branch, err := git.CurrentBranch(ctx, opts.Repo.Root)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
reportProgress(opts.Progress, "Pushing patch repo to %s/%s", opts.Remote, branch)
|
|
if err := git.Push(ctx, opts.Repo.Root, opts.Remote, branch); err != nil {
|
|
return nil, err
|
|
}
|
|
return &PublishResult{Remote: opts.Remote, Branch: branch, Message: opts.Message}, nil
|
|
}
|