2019-12-20 20:47:50 +00:00
|
|
|
// Copyright (c) 2019, the Drone Plugins project authors.
|
|
|
|
// Please see the AUTHORS file for details. All rights reserved.
|
|
|
|
// Use of this source code is governed by an Apache 2.0 license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
package drone
|
|
|
|
|
2020-09-14 20:28:34 +00:00
|
|
|
import "strings"
|
|
|
|
|
2020-09-10 18:01:00 +00:00
|
|
|
type (
|
|
|
|
// Commit represents the current commit being built.
|
|
|
|
Commit struct {
|
|
|
|
// SHA for the current commit.
|
|
|
|
SHA string
|
2019-12-20 20:47:50 +00:00
|
|
|
|
2020-09-10 18:01:00 +00:00
|
|
|
// Before contains the commit sha before the patch is applied.
|
|
|
|
Before string
|
2019-12-20 20:47:50 +00:00
|
|
|
|
2020-09-10 18:01:00 +00:00
|
|
|
// After contains the commit sha after the patch is applied.
|
|
|
|
After string
|
2019-12-20 20:47:50 +00:00
|
|
|
|
2020-09-10 18:01:00 +00:00
|
|
|
// Ref for the current commit.
|
|
|
|
Ref string
|
2019-12-20 20:47:50 +00:00
|
|
|
|
2020-09-10 18:01:00 +00:00
|
|
|
// Branch target for the push or pull request. This may be empty for
|
|
|
|
// tag events.
|
|
|
|
Branch string
|
2019-12-20 20:47:50 +00:00
|
|
|
|
2020-09-10 18:01:00 +00:00
|
|
|
// Link to the commit or object in the source control management system.
|
|
|
|
Link string
|
2019-12-20 20:47:50 +00:00
|
|
|
|
2020-09-10 18:01:00 +00:00
|
|
|
// Message for the current commit.
|
|
|
|
Message Message
|
2019-12-20 20:47:50 +00:00
|
|
|
|
2020-09-10 18:01:00 +00:00
|
|
|
// Author of the commit.
|
|
|
|
Author Author
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2020-09-11 13:36:07 +00:00
|
|
|
func (c Commit) String() string {
|
|
|
|
return c.SHA
|
|
|
|
}
|
|
|
|
|
2020-09-10 18:01:00 +00:00
|
|
|
func (a Author) String() string {
|
|
|
|
return a.Username
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m Message) String() string {
|
2020-09-14 20:28:34 +00:00
|
|
|
if m.Body == "" {
|
|
|
|
return m.Title
|
|
|
|
}
|
|
|
|
|
|
|
|
return m.Title + "\n\n" + m.Body
|
|
|
|
}
|
|
|
|
|
|
|
|
// ParseMessage takes a full commit message and translates it into a Message.
|
|
|
|
func ParseMessage(msg string) Message {
|
|
|
|
splitMsg := strings.Split(msg, "\n")
|
|
|
|
|
|
|
|
return Message{
|
|
|
|
Title: strings.TrimSpace(splitMsg[0]),
|
|
|
|
Body: strings.TrimSpace(strings.Join(splitMsg[1:], "\n")),
|
|
|
|
}
|
2019-12-20 20:47:50 +00:00
|
|
|
}
|