mirror of
https://github.com/thegeeklab/drone-plugin-lib.git
synced 2024-11-22 10:50:39 +00:00
Split Author and Message from Commit
The drone-slack plugin has structs for Author and Message. Since this is the most popular notification plugin it makes sense to follow along with it.
This commit is contained in:
parent
a8409c1215
commit
c5ec06ee53
@ -5,8 +5,9 @@
|
|||||||
|
|
||||||
package drone
|
package drone
|
||||||
|
|
||||||
// Commit represents the current commit being built.
|
type (
|
||||||
type Commit struct {
|
// Commit represents the current commit being built.
|
||||||
|
Commit struct {
|
||||||
// SHA for the current commit.
|
// SHA for the current commit.
|
||||||
SHA string
|
SHA string
|
||||||
|
|
||||||
@ -27,10 +28,10 @@ type Commit struct {
|
|||||||
Link string
|
Link string
|
||||||
|
|
||||||
// Message for the current commit.
|
// Message for the current commit.
|
||||||
Message string
|
Message Message
|
||||||
|
|
||||||
// Author of the commit.
|
// Author of the commit.
|
||||||
Author string
|
Author Author
|
||||||
|
|
||||||
// AuthorName of the commit.
|
// AuthorName of the commit.
|
||||||
AuthorName string
|
AuthorName string
|
||||||
@ -40,4 +41,33 @@ type Commit struct {
|
|||||||
|
|
||||||
// AuthorAvatar of the commit.
|
// AuthorAvatar of the commit.
|
||||||
AuthorAvatar string
|
AuthorAvatar string
|
||||||
|
}
|
||||||
|
|
||||||
|
// Author of a Commit.
|
||||||
|
Author struct {
|
||||||
|
// Username of the Commit author.
|
||||||
|
Username string
|
||||||
|
// Name of the Commit author.
|
||||||
|
Name string
|
||||||
|
// Email for the Commit author.
|
||||||
|
Email string
|
||||||
|
// Avatar for the Commit author.
|
||||||
|
Avatar string
|
||||||
|
}
|
||||||
|
|
||||||
|
// Message for a Commit.
|
||||||
|
Message struct {
|
||||||
|
// Title for the Commit.
|
||||||
|
Title string
|
||||||
|
// Body of the Commit message.
|
||||||
|
Body string
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func (a Author) String() string {
|
||||||
|
return a.Username
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m Message) String() string {
|
||||||
|
return m.Title + m.Body
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,8 @@
|
|||||||
package urfave
|
package urfave
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/drone-plugins/drone-plugin-lib/drone"
|
"github.com/drone-plugins/drone-plugin-lib/drone"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
)
|
)
|
||||||
@ -95,6 +97,8 @@ func commitFlags() []cli.Flag {
|
|||||||
|
|
||||||
// commitFromContext creates a drone.Commit from the cli.Context.
|
// commitFromContext creates a drone.Commit from the cli.Context.
|
||||||
func commitFromContext(ctx *cli.Context) drone.Commit {
|
func commitFromContext(ctx *cli.Context) drone.Commit {
|
||||||
|
splitMsg := strings.Split(ctx.String("commit.message"), "\n")
|
||||||
|
|
||||||
return drone.Commit{
|
return drone.Commit{
|
||||||
SHA: ctx.String("commit.sha"),
|
SHA: ctx.String("commit.sha"),
|
||||||
Before: ctx.String("commit.before"),
|
Before: ctx.String("commit.before"),
|
||||||
@ -102,10 +106,15 @@ func commitFromContext(ctx *cli.Context) drone.Commit {
|
|||||||
Ref: ctx.String("commit.ref"),
|
Ref: ctx.String("commit.ref"),
|
||||||
Branch: ctx.String("commit.branch"),
|
Branch: ctx.String("commit.branch"),
|
||||||
Link: ctx.String("commit.link"),
|
Link: ctx.String("commit.link"),
|
||||||
Message: ctx.String("commit.message"),
|
Message: drone.Message{
|
||||||
Author: ctx.String("commit.author"),
|
Title: strings.TrimSpace(splitMsg[0]),
|
||||||
AuthorName: ctx.String("commit.author-name"),
|
Body: strings.TrimSpace(strings.Join(splitMsg[1:], "\n")),
|
||||||
AuthorEmail: ctx.String("commit.author-email"),
|
},
|
||||||
AuthorAvatar: ctx.String("commit.author-avatar"),
|
Author: drone.Author{
|
||||||
|
Username: ctx.String("commit.author"),
|
||||||
|
Name: ctx.String("commit.author-name"),
|
||||||
|
Email: ctx.String("commit.author-email"),
|
||||||
|
Avatar: ctx.String("commit.author-avatar"),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user