feat: add support for specifying source branch in build configuration

- Add a new flag `source.branch` with default value `develop` and usage description "git source branch"
- Add a new struct `Source` with a `Branch` field
- Add a new field `Source` to the existing struct `Build`
- Add a new test case with `Source.Branch` set to "feature/awesome-feature"

Signed-off-by: appleboy <appleboy.tw@gmail.com>
This commit is contained in:
appleboy
2023-12-24 19:09:34 +08:00
parent 881339ea8f
commit 692f7ff6dd
3 changed files with 17 additions and 0 deletions
+9
View File
@@ -143,6 +143,12 @@ func main() {
Usage: "commit message",
EnvVar: "DRONE_COMMIT_MESSAGE",
},
cli.StringFlag{
Name: "source.branch",
Value: "develop",
Usage: "git source branch",
EnvVar: "DRONE_SOURCE_BRANCH",
},
cli.StringFlag{
Name: "build.event",
Value: "push",
@@ -251,6 +257,9 @@ func run(c *cli.Context) error {
Avatar: c.String("commit.author.avatar"),
Message: c.String("commit.message"),
},
Source: Source{
Branch: c.String("source.branch"),
},
Build: Build{
Tag: c.String("build.tag"),
Number: c.Int("build.number"),
+5
View File
@@ -52,6 +52,10 @@ type (
Message string
}
Source struct {
Branch string
}
// Build information.
Build struct {
Tag string
@@ -121,6 +125,7 @@ type (
GitHub GitHub
Repo Repo
Build Build
Source Source
Config Config
Payload Payload
Commit Commit
+3
View File
@@ -34,6 +34,9 @@ func TestTemplate(t *testing.T) {
Link: "https://github.com/appleboy/go-hello",
Event: "tag",
},
Source: Source{
Branch: "feature/awesome-feature",
},
Config: Config{
WebhookID: os.Getenv("WEBHOOK_ID"),