Skip to content

Commit

Permalink
feature(main): fix auto get repo name
Browse files Browse the repository at this point in the history
  • Loading branch information
cuisongliu committed Apr 29, 2023
1 parent 294a0b1 commit cbe5858
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
4 changes: 1 addition & 3 deletions .github/gh-bot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ bot:
email: [email protected]
username: sealos-ci-robot
repo:
org: true
name: labring-actions/sealos
fork: cuisongliu/sealos
org: false

release:
retry: 15s
Expand Down
14 changes: 7 additions & 7 deletions cmd/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,7 @@ import (
)

func preCheck() error {
var err error
types.GlobalsGithubVar, err = types.GetGHEnvToVar()
if err != nil {
return err
}
logger.Debug("github env to var: %v", types.GlobalsGithubVar)
if err = checkGithubEnv(); err != nil {
if err := checkGithubEnv(); err != nil {
return err
}
return nil
Expand All @@ -55,6 +49,12 @@ func checkGithubEnv() error {

func checkToken() {
var err error
types.GlobalsGithubVar, err = types.GetGHEnvToVar()
if err != nil {
logger.Error(err)
os.Exit(1)
}
logger.Debug("github env to var: %v", types.GlobalsGithubVar)
types.GlobalsBotConfig, err = types.LoadConfig(cfgFile)
if err != nil {
logger.Error(err)
Expand Down
6 changes: 6 additions & 0 deletions pkg/types/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,17 @@ func (r *Config) GetOrgCommand() string {

// GetRepoName returns the name for the repo
func (r *Config) GetRepoName() string {
if r.Repo.Name == "" {
r.Repo.Name = fmt.Sprintf("%s/%s", r.Bot.Username, GlobalsGithubVar.RepoName)
}
return r.Repo.Name
}

// GetForkName returns the fork for the repo
func (r *Config) GetForkName() string {
if r.Repo.Fork == "" {
r.Repo.Fork = GlobalsGithubVar.SafeRepo
}
return r.Repo.Fork
}

Expand Down
2 changes: 2 additions & 0 deletions pkg/types/gh_env.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
type GithubVar struct {
RunnerID string
SafeRepo string
RepoName string
IssueOrPRNumber int64
CommentBody string
SenderOrCommentUser string
Expand Down Expand Up @@ -61,6 +62,7 @@ func GetGHEnvToVar() (*GithubVar, error) {
}
gVar.IssueOrPRNumber = id
gVar.SafeRepo, _, _ = unstructured.NestedString(mData, "repository", "full_name")
gVar.RepoName, _, _ = unstructured.NestedString(mData, "repository", "name")
gVar.CommentBody, _, _ = unstructured.NestedString(mData, "comment", "body")

user, ok, _ := unstructured.NestedString(mData, "comment", "user", "login")
Expand Down

0 comments on commit cbe5858

Please sign in to comment.