feat(cmd): load groups from env
This commit is contained in:
		
							parent
							
								
									6ddd403f08
								
							
						
					
					
						commit
						e8c6e87b94
					
				
							
								
								
									
										12
									
								
								cmd/joj3/env/env.go
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										12
									
								
								cmd/joj3/env/env.go
									
									
									
									
										vendored
									
									
								
							|  | @ -6,6 +6,12 @@ import ( | ||||||
| 	"time" | 	"time" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
|  | const ( | ||||||
|  | 	ConfName = "JOJ3_CONF_NAME" | ||||||
|  | 	Groups   = "JOJ3_GROUPS" | ||||||
|  | 	RunID    = "JOJ3_RUN_ID" | ||||||
|  | ) | ||||||
|  | 
 | ||||||
| type Attribute struct { | type Attribute struct { | ||||||
| 	ConfName   string | 	ConfName   string | ||||||
| 	Groups     string | 	Groups     string | ||||||
|  | @ -42,7 +48,7 @@ func init() { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func Set() { | func Set() { | ||||||
| 	os.Setenv("JOJ3_CONF_NAME", Attr.ConfName) | 	os.Setenv(ConfName, Attr.ConfName) | ||||||
| 	os.Setenv("JOJ3_GROUPS", Attr.Groups) | 	os.Setenv(Groups, Attr.Groups) | ||||||
| 	os.Setenv("JOJ3_RUN_ID", Attr.RunID) | 	os.Setenv(RunID, Attr.RunID) | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -6,7 +6,9 @@ import ( | ||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"log/slog" | 	"log/slog" | ||||||
| 	"os" | 	"os" | ||||||
|  | 	"strings" | ||||||
| 
 | 
 | ||||||
|  | 	"github.com/joint-online-judge/JOJ3/cmd/joj3/env" | ||||||
| 	"github.com/joint-online-judge/JOJ3/internal/conf" | 	"github.com/joint-online-judge/JOJ3/internal/conf" | ||||||
| 	"github.com/joint-online-judge/JOJ3/pkg/healthcheck" | 	"github.com/joint-online-judge/JOJ3/pkg/healthcheck" | ||||||
| ) | ) | ||||||
|  | @ -61,22 +63,12 @@ func init() { | ||||||
| func prepareTeapotCheck() ( | func prepareTeapotCheck() ( | ||||||
| 	confObj *conf.Conf, groups []string, err error, | 	confObj *conf.Conf, groups []string, err error, | ||||||
| ) { | ) { | ||||||
| 	commitMsg, err := conf.GetCommitMsg() |  | ||||||
| 	if err != nil { |  | ||||||
| 		slog.Error("get commit msg", "error", err) |  | ||||||
| 		return |  | ||||||
| 	} |  | ||||||
| 	conventionalCommit, err := conf.ParseConventionalCommit(commitMsg) |  | ||||||
| 	if err != nil { |  | ||||||
| 		slog.Error("parse commit msg", "error", err) |  | ||||||
| 		return |  | ||||||
| 	} |  | ||||||
| 	confObj, err = conf.ParseConfFile(confPath) | 	confObj, err = conf.ParseConfFile(confPath) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		slog.Error("parse conf", "error", err) | 		slog.Error("parse conf", "error", err) | ||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
| 	groups = conf.MatchGroups(confObj, conventionalCommit) | 	groups = strings.Split(os.Getenv(env.Groups), ",") | ||||||
| 	return | 	return | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user