Skip to content

Commit

Permalink
feature(main): add rebot code
Browse files Browse the repository at this point in the history
  • Loading branch information
cuisongliu committed Apr 27, 2023
1 parent aae2a57 commit 0d5e3c0
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 219 deletions.
15 changes: 0 additions & 15 deletions .github/gh-bot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,6 @@ repo:
name: labring-actions/sealos
fork: cuisongliu/sealos

changelog:
script: scripts/changelog.sh {{.Repo.Fork}}
allowOps:
- cuisongliu
reviewers:
- cuisongliu
title: "docs: Automated Changelog Update for {{.ReleaseVersion}}"
body: |
🤖 add release changelog using rebot.<br/>
copilot:all
release:
retry: 15s
action: Release
Expand All @@ -40,8 +29,4 @@ message:
release_error: |
🤖 says: ‼️ Release action failed.
Error details: {{.Error}}
changelog_error: |
🤖 says: ‼️ Changelog action encountered an error.
Error details: {{.Error}}
27 changes: 1 addition & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,6 @@ repo:
name: labring-actions/sealos
fork: cuisongliu/sealos

changelog:
title: "docs: Automated Changelog Update for {{.ReleaseVersion}}"
body: |
🤖 add release changelog using rebot.<br/>
copilot:all
script: scripts/changelog.sh
allowOps:
- cuisongliu
reviewers:
- cuisongliu

release:
retry: 15s
action: Release
Expand All @@ -48,8 +37,6 @@ message:
🤖 says: ‼️ The action no has permission to trigger.
release_error: |
🤖 says: ‼️ The action release error.
changelog_error: |
🤖 says: ‼️ The action changelog error.
```

Expand All @@ -67,12 +54,6 @@ message:
- `org` - 是否为组织仓库,设置为 true 时表示是组织仓库。
- `name` - 仓库名称。
- `fork` - fork 的仓库名称。
- `changelog` \- 变更日志配置。
- `title` - 变更日志标题模板。`ReleaseVersion`为当前版本号
- `body` - 变更日志内容模板。`ReleaseVersion`为当前版本号
- `script` - 生成变更日志的脚本。默认值 `scripts/changelog.sh`,可使用模板渲染。
- `allowOps` - 允许触发变更日志操作的用户名列表。
- `reviewers` - 审核者列表。
- `release` \- 发布配置。
- `retry` - 重试间隔,例如:15s。
- `action` - 执行动作,例如:Release。
Expand All @@ -82,7 +63,6 @@ message:
- `format_error` - 格式错误消息模板。
- `permission_error` - 权限错误消息模板。
- `release_error` - 发布错误消息模板。
- `changelog_error` - 变更日志错误消息模板。

## 使用文档

Expand All @@ -94,13 +74,9 @@ message:

### 变更日志操作

如果需要生成变更日志,请在 issue 或 PR 中使用以下命令:
之前的操作已经废弃,使用 https://github.com/labring/sealos/blob/d528d6be713b9b9cf92169e5822d354d29fffb9d/.github/workflows/release.yml#L72

```bash
/sealos_changelog
```

此命令会触发配置文件中定义的脚本(如本例中的 `scripts/changelog.sh`)来生成变更日志。需要注意的是,只有在 `changelog` 配置节中的 `allowOps` 列表中的用户才有权限触发此操作。

### 发布操作

Expand All @@ -117,7 +93,6 @@ message:
- 格式错误:‼️ 机器人说:操作格式错误,请检查此操作的格式。
- 权限错误:‼️ 机器人说:操作无权限触发。
- 发布错误:‼️ 机器人说:操作发布错误。
- 变更日志错误:‼️ 机器人说:操作变更日志错误。

在遇到错误时,请根据提示信息进行相应的调整。

Expand Down
3 changes: 0 additions & 3 deletions cmd/comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ var commentCmd = &cobra.Command{
for _, t := range cmds {
logger.Debug("cmds: ", strings.TrimSpace(t))
wfs := make([]workflow.Interface, 0)
if types.GlobalsBotConfig.Changelog != nil {
wfs = append(wfs, workflow.NewChangelog(strings.TrimSpace(t)))
}
if types.GlobalsBotConfig.Release != nil {
wfs = append(wfs, workflow.NewRelease(strings.TrimSpace(t)))
}
Expand Down
79 changes: 0 additions & 79 deletions pkg/gh/changelog.go

This file was deleted.

40 changes: 18 additions & 22 deletions pkg/gh/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,22 @@ limitations under the License.
package gh

const (
authStatus = "gh auth status"
disablePrompt = "gh config set prompt disabled"
configEmail = "cd /tmp/fork-sealos-repo && git config user.email %s"
configUser = "cd /tmp/fork-sealos-repo && git config user.name %s"
forkRepo = "gh repo view %s >/dev/null 2>&1 || (echo '仓库不存在,正在fork仓库...' && gh repo fork %s %s)"
syncRepo = "cd /tmp/fork-sealos-repo && git fetch fork && git rebase fork/main && git push -f origin main && git fetch --tags fork && git push -f --tags origin"
cloneRepo = "rm -rf /tmp/fork-sealos-repo && gh repo clone %s /tmp/fork-sealos-repo"
checkRepo = "gh repo view %s --json isFork,url,name,isArchived -q '.'"
setToken = "cd /tmp/fork-sealos-repo && git remote set-url origin https://%s:%s@github.com/%s.git"
newBranch = "cd /tmp/fork-sealos-repo && git checkout -b %s"
generateChangelog = "cd /tmp/fork-sealos-repo && bash %s"
gitStatus = "cd /tmp/fork-sealos-repo && git status"
gitAdd = "cd /tmp/fork-sealos-repo && git add -A"
gitCommit = "cd /tmp/fork-sealos-repo && git commit -am '%s' -s"
gitRelease = "cd /tmp/fork-sealos-repo && git describe --abbrev=0 --tags"
gitPush = "cd /tmp/fork-sealos-repo && git push -u origin %s"
gitPRTmpl = "cd /tmp/fork-sealos-repo && gh pr create --title '{{.Title}}' --body '{{.Body}}' --reviewer {{.Reviewers}} "
gitTag = "cd /tmp/fork-sealos-repo && git fetch --tags && git tag -l"
gitNewTag = "cd /tmp/fork-sealos-repo && git tag %s"
gitAddRemote = "cd /tmp/fork-sealos-repo && git remote add fork https://%s:%s@github.com/%s.git"
gitPushRemote = "cd /tmp/fork-sealos-repo && git push -f fork %s"
gitWorkflowCheck = "cd /tmp/fork-sealos-repo && gh run list --repo %s -w %s --json name,status,url,conclusion,headBranch -q '.[]|select(.headBranch==\"%s\")'"
authStatus = "gh auth status"
disablePrompt = "gh config set prompt disabled"
configEmail = "cd /tmp/fork-sealos-repo && git config user.email %s"
configUser = "cd /tmp/fork-sealos-repo && git config user.name %s"
forkRepo = "gh repo view %s >/dev/null 2>&1 || (echo '仓库不存在,正在fork仓库...' && gh repo fork %s %s)"
syncRepo = "cd /tmp/fork-sealos-repo && git fetch fork && git rebase fork/main && git push -f origin main && git fetch --tags fork && git push -f --tags origin"
cloneRepo = "rm -rf /tmp/fork-sealos-repo && gh repo clone %s /tmp/fork-sealos-repo"
checkRepo = "gh repo view %s --json isFork,url,name,isArchived -q '.'"
setToken = "cd /tmp/fork-sealos-repo && git remote set-url origin https://%s:%s@github.com/%s.git"
gitStatus = "cd /tmp/fork-sealos-repo && git status"
gitAdd = "cd /tmp/fork-sealos-repo && git add -A"
gitCommit = "cd /tmp/fork-sealos-repo && git commit -am '%s' -s"
gitRelease = "cd /tmp/fork-sealos-repo && git describe --abbrev=0 --tags"
gitTag = "cd /tmp/fork-sealos-repo && git fetch --tags && git tag -l"
gitNewTag = "cd /tmp/fork-sealos-repo && git tag %s"
gitAddRemote = "cd /tmp/fork-sealos-repo && git remote add fork https://%s:%s@github.com/%s.git"
gitPushRemote = "cd /tmp/fork-sealos-repo && git push -f fork %s"
gitWorkflowCheck = "cd /tmp/fork-sealos-repo && gh run list --repo %s -w %s --json name,status,url,conclusion,headBranch -q '.[]|select(.headBranch==\"%s\")'"
)
22 changes: 22 additions & 0 deletions pkg/gh/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ package gh

import (
"fmt"
"github.com/cuisongliu/logger"
"github.com/labring-actions/gh-rebot/pkg/types"
"github.com/labring-actions/gh-rebot/pkg/utils"
"math/rand"
"strings"
Expand Down Expand Up @@ -84,3 +86,23 @@ func checkRemoteTagExists(tag string) (bool, error) {

return false, nil
}

func setPreGithub() error {
shells := []any{
authStatus,
disablePrompt,
fmt.Sprintf(forkRepo, types.GlobalsBotConfig.GetRepoName(), types.GlobalsBotConfig.GetForkName(), types.GlobalsBotConfig.GetOrgCommand()),
types.RetryShell(fmt.Sprintf(checkRepo, types.GlobalsBotConfig.GetRepoName())),
types.RetryShell(fmt.Sprintf(cloneRepo, types.GlobalsBotConfig.GetRepoName())),
fmt.Sprintf(configEmail, types.GlobalsBotConfig.GetEmail()),
fmt.Sprintf(configUser, types.GlobalsBotConfig.GetUsername()),
types.SecretShell(fmt.Sprintf(setToken, types.GlobalsBotConfig.GetUsername(), types.GlobalsBotConfig.GetToken(), types.GlobalsBotConfig.GetRepoName())),
types.SecretShell(fmt.Sprintf(gitAddRemote, types.GlobalsBotConfig.GetUsername(), types.GlobalsBotConfig.GetToken(), types.GlobalsBotConfig.GetForkName())),
fmt.Sprintf(syncRepo),
}
if err := types.ExecShellForAny(types.GlobalsBotConfig.GetToken())(shells); err != nil {
logger.Error("setPreGithub err:%v", err)
return err
}
return nil
}
18 changes: 1 addition & 17 deletions pkg/types/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ type Config struct {
Message map[string]string `json:"message"`
Token string `json:"-"`

Changelog *Changelog `json:"changelog,omitempty"`
Release *Release `json:"release,omitempty"`
Release *Release `json:"release,omitempty"`
}

func (r *Config) Validate() error {
Expand All @@ -72,14 +71,6 @@ func (r *Config) Validate() error {
if r.Repo.Fork == "" {
return fmt.Errorf("repo fork is required")
}
if r.Changelog != nil {
if r.Changelog.Body == "" {
return fmt.Errorf("changelog body is required")
}
if r.Changelog.Title == "" {
return fmt.Errorf("changelog title is required")
}
}
if r.Release != nil {
if r.Release.Action == "" {
return fmt.Errorf("release action is required")
Expand Down Expand Up @@ -154,10 +145,3 @@ func (c *Config) GetMessage(key string) string {
}
return ""
}

func (c *Config) GetChangelogScript() string {
if c.Changelog.Script == "" {
return "scripts/changelog.sh"
}
return c.Changelog.Script
}
57 changes: 0 additions & 57 deletions pkg/workflow/changelog.go

This file was deleted.

0 comments on commit 0d5e3c0

Please sign in to comment.