mirror of
https://github.com/thegeeklab/drone-plugin-lib.git
synced 2024-11-22 00:40: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,39 +5,69 @@
|
|||||||
|
|
||||||
package drone
|
package drone
|
||||||
|
|
||||||
// Commit represents the current commit being built.
|
type (
|
||||||
type Commit struct {
|
// Commit represents the current commit being built.
|
||||||
// SHA for the current commit.
|
Commit struct {
|
||||||
SHA string
|
// SHA for the current commit.
|
||||||
|
SHA string
|
||||||
|
|
||||||
// Before contains the commit sha before the patch is applied.
|
// Before contains the commit sha before the patch is applied.
|
||||||
Before string
|
Before string
|
||||||
|
|
||||||
// After contains the commit sha after the patch is applied.
|
// After contains the commit sha after the patch is applied.
|
||||||
After string
|
After string
|
||||||
|
|
||||||
// Ref for the current commit.
|
// Ref for the current commit.
|
||||||
Ref string
|
Ref string
|
||||||
|
|
||||||
// Branch target for the push or pull request. This may be empty for
|
// Branch target for the push or pull request. This may be empty for
|
||||||
// tag events.
|
// tag events.
|
||||||
Branch string
|
Branch string
|
||||||
|
|
||||||
// Link to the commit or object in the source control management system.
|
// Link to the commit or object in the source control management system.
|
||||||
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
|
||||||
|
|
||||||
// AuthorEmail of the commit.
|
// AuthorEmail of the commit.
|
||||||
AuthorEmail string
|
AuthorEmail string
|
||||||
|
|
||||||
// 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,17 +97,24 @@ 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"),
|
||||||
After: ctx.String("commit.after"),
|
After: ctx.String("commit.after"),
|
||||||
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