-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: some refactors and fix some typo
Signed-off-by: Bird <aflybird0@gmail.com>
- Loading branch information
Showing
25 changed files
with
209 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,49 @@ | ||
package ci | ||
|
||
import "github.com/devstream-io/devstream/pkg/util/file" | ||
|
||
type ciRepoType string | ||
|
||
const ( | ||
defaultBranch = "feat-repo-ci-update" | ||
defaultCommitMsg = "update ci config" | ||
ciJenkinsConfigLocation = "Jenkinsfile" | ||
ciGitHubWorkConfigLocation = ".github/workflows" | ||
ciGitLabConfigLocation = ".gitlab-ci.yml" | ||
ciJenkinsType ciRepoType = "jenkins" | ||
ciGitLabType ciRepoType = "gitlab" | ||
ciGitHubType ciRepoType = "github" | ||
deleteCommitMsg = "delete ci files" | ||
defaultBranch = "feat-repo-ci-update" | ||
defaultCommitMsg = "update ci config" | ||
|
||
ciJenkinsConfigLocation = "Jenkinsfile" | ||
ciGitHubWorkConfigLocation = ".github/workflows" | ||
ciGitLabConfigLocation = ".gitlab-ci.yml" | ||
|
||
ciJenkinsType ciRepoType = "jenkins" | ||
ciGitLabType ciRepoType = "gitlab" | ||
ciGitHubType ciRepoType = "github" | ||
|
||
deleteCommitMsg = "delete ci files" | ||
) | ||
|
||
type CI interface { | ||
// Type return ci type | ||
Type() ciRepoType | ||
// CIFilePath returns the file path of ci config file | ||
// gitlab and jenkins is just a file, so we can just use filename | ||
// but GitHub use directory, we should process this situation | ||
// for GitHub: return ".github/workflows" or ".github/workflows/subFilename" | ||
// for gitlab, jenkins: will ignore subFilename param | ||
CIFilePath(subFilename ...string) string | ||
// filterCIFilesFunc returns a filter function to select ci config file | ||
filterCIFilesFunc() file.DirFIleFilterFunc | ||
// getGitNameFunc returns a function to transform file path to git name of ci config file | ||
getGitNameFunc() file.DirFileNameFunc | ||
} | ||
|
||
func NewCI(ciType ciRepoType) CI { | ||
// there are no validation for ciType | ||
// because we have already validated it by `validate` flag in CIConfig.Type | ||
switch ciType { | ||
case ciGitLabType: | ||
return &GitLabCI{} | ||
case ciGitHubType: | ||
return &GitHubCI{} | ||
case ciJenkinsType: | ||
return &JenkinsCI{} | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package ci | ||
|
||
import ( | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/devstream-io/devstream/pkg/util/file" | ||
) | ||
|
||
type GitHubCI struct { | ||
} | ||
|
||
func (g *GitHubCI) Type() ciRepoType { | ||
return ciGitHubType | ||
} | ||
|
||
func (g *GitHubCI) CIFilePath(subFilename ...string) string { | ||
// if subFilename is empty, return dir(.github/workflows) | ||
if len(subFilename) == 0 { | ||
return ciGitHubWorkConfigLocation | ||
} | ||
// else return dir + subFilename | ||
return filepath.Join(ciGitHubWorkConfigLocation, filepath.Base(subFilename[0])) | ||
} | ||
|
||
func (g *GitHubCI) filterCIFilesFunc() file.DirFIleFilterFunc { | ||
return func(filePath string, isDir bool) bool { | ||
// not process dir | ||
if isDir { | ||
return false | ||
} | ||
return strings.Contains(filePath, "workflows") | ||
} | ||
} | ||
|
||
func (g *GitHubCI) getGitNameFunc() file.DirFileNameFunc { | ||
return func(filePath, walkDir string) string { | ||
return g.CIFilePath(filePath) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package ci | ||
|
||
import ( | ||
"path/filepath" | ||
|
||
"github.com/devstream-io/devstream/pkg/util/file" | ||
) | ||
|
||
type GitLabCI struct { | ||
} | ||
|
||
func (g *GitLabCI) Type() ciRepoType { | ||
return ciGitLabType | ||
} | ||
|
||
func (g *GitLabCI) CIFilePath(_ ...string) string { | ||
return ciGitLabConfigLocation | ||
} | ||
|
||
func (g *GitLabCI) filterCIFilesFunc() file.DirFIleFilterFunc { | ||
return func(filePath string, isDir bool) bool { | ||
// not process dir | ||
if isDir { | ||
return false | ||
} | ||
return filepath.Base(filePath) == g.CIFilePath() | ||
} | ||
} | ||
|
||
func (g *GitLabCI) getGitNameFunc() file.DirFileNameFunc { | ||
return func(filePath, walkDir string) string { | ||
return g.CIFilePath() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package ci | ||
|
||
import "github.com/devstream-io/devstream/pkg/util/file" | ||
|
||
type JenkinsCI struct { | ||
} | ||
|
||
func (j *JenkinsCI) Type() ciRepoType { | ||
return ciJenkinsType | ||
} | ||
|
||
func (j *JenkinsCI) CIFilePath(_ ...string) string { | ||
return ciJenkinsConfigLocation | ||
} | ||
|
||
func (j *JenkinsCI) filterCIFilesFunc() file.DirFIleFilterFunc { | ||
return func(filePath string, isDir bool) bool { | ||
// not process dir | ||
if isDir { | ||
return false | ||
} | ||
return filePath == ciJenkinsConfigLocation | ||
} | ||
} | ||
|
||
func (j *JenkinsCI) getGitNameFunc() file.DirFileNameFunc { | ||
return func(filePath, walkDir string) string { | ||
return j.CIFilePath() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.