mirror of
https://codeberg.org/woodpecker-plugins/go-plugin.git
synced 2024-11-10 00:45:38 +01:00
67b6cdf4a6
Reviewed-on: https://codeberg.org/woodpecker-plugins/go-plugin/pulls/29 Reviewed-by: Patrick Schratz <pat-s@noreply.codeberg.org> Co-authored-by: 6543 <6543@obermui.de> Co-committed-by: 6543 <6543@obermui.de>
241 lines
5.8 KiB
Go
241 lines
5.8 KiB
Go
// Copyright 2023 Woodpecker Authors
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package plugin
|
|
|
|
import (
|
|
"github.com/urfave/cli/v3"
|
|
)
|
|
|
|
type (
|
|
// Commit defines runtime metadata for a commit.
|
|
Commit struct {
|
|
Sha string `json:"sha,omitempty"`
|
|
Ref string `json:"ref,omitempty"`
|
|
Refspec string `json:"refspec,omitempty"`
|
|
PullRequest string `json:"pull_request,omitempty"`
|
|
SourceBranch string `json:"source_branch,omitempty"`
|
|
TargetBranch string `json:"target_branch,omitempty"`
|
|
Branch string `json:"branch,omitempty"`
|
|
Tag string `json:"tag,omitempty"`
|
|
Message string `json:"message,omitempty"`
|
|
Author Author `json:"author,omitempty"`
|
|
}
|
|
|
|
// Author defines runtime metadata for a commit author.
|
|
Author struct {
|
|
Name string `json:"name,omitempty"`
|
|
Email string `json:"email,omitempty"`
|
|
Avatar string `json:"avatar,omitempty"`
|
|
}
|
|
)
|
|
|
|
func commitFlags() []cli.Flag {
|
|
return []cli.Flag{
|
|
&cli.StringFlag{
|
|
Name: "commit.sha",
|
|
Usage: "commit SHA",
|
|
Sources: cli.EnvVars(
|
|
"CI_COMMIT_SHA",
|
|
"DRONE_COMMIT",
|
|
"DRONE_COMMIT_SHA",
|
|
),
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "commit.ref",
|
|
Usage: "commit ref",
|
|
Sources: cli.EnvVars(
|
|
"CI_COMMIT_REF",
|
|
"DRONE_COMMIT_REF",
|
|
),
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "commit.refspec",
|
|
Usage: "commit refspec",
|
|
Sources: cli.EnvVars(
|
|
"CI_COMMIT_REFSPEC",
|
|
),
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "commit.pull-request",
|
|
Usage: "commit pull request",
|
|
Sources: cli.EnvVars(
|
|
"CI_COMMIT_PULL_REQUEST",
|
|
"DRONE_PULL_REQUEST",
|
|
),
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "commit.source-branch",
|
|
Usage: "commit source branch",
|
|
Sources: cli.EnvVars(
|
|
"CI_COMMIT_SOURCE_BRANCH",
|
|
"DRONE_SOURCE_BRANCH",
|
|
),
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "commit.target-branch",
|
|
Usage: "commit target branch",
|
|
Sources: cli.EnvVars(
|
|
"CI_COMMIT_TARGET_BRANCH",
|
|
"DRONE_TARGET_BRANCH",
|
|
),
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "commit.branch",
|
|
Usage: "commit branch",
|
|
Sources: cli.EnvVars(
|
|
"CI_COMMIT_BRANCH",
|
|
"DRONE_BRANCH",
|
|
),
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "commit.tag",
|
|
Usage: "commit tag",
|
|
Sources: cli.EnvVars(
|
|
"CI_COMMIT_TAG",
|
|
"DRONE_TAG",
|
|
),
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "commit.message",
|
|
Usage: "commit message",
|
|
Sources: cli.EnvVars(
|
|
"CI_COMMIT_MESSAGE",
|
|
"DRONE_COMMIT_MESSAGE",
|
|
),
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "commit.author.name",
|
|
Usage: "commit author name",
|
|
Sources: cli.EnvVars(
|
|
"CI_COMMIT_AUTHOR",
|
|
"DRONE_COMMIT_AUTHOR",
|
|
"DRONE_COMMIT_AUTHOR_NAME",
|
|
),
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "commit.author.email",
|
|
Usage: "commit author email",
|
|
Sources: cli.EnvVars(
|
|
"CI_COMMIT_AUTHOR_EMAIL",
|
|
"DRONE_COMMIT_AUTHOR_EMAIL",
|
|
),
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "commit.author.avatar",
|
|
Usage: "commit author avatar",
|
|
Sources: cli.EnvVars(
|
|
"CI_COMMIT_AUTHOR_AVATAR",
|
|
"DRONE_COMMIT_AUTHOR_AVATAR",
|
|
),
|
|
},
|
|
}
|
|
}
|
|
|
|
func commitFromContext(c *cli.Command) Commit {
|
|
return Commit{
|
|
Sha: c.String("commit.sha"),
|
|
Ref: c.String("commit.ref"),
|
|
Refspec: c.String("commit.refspec"),
|
|
PullRequest: c.String("commit.pull-request"),
|
|
SourceBranch: c.String("commit.source-branch"),
|
|
TargetBranch: c.String("commit.target-branch"),
|
|
Branch: c.String("commit.branch"),
|
|
Tag: c.String("commit.tag"),
|
|
Message: c.String("commit.message"),
|
|
Author: Author{
|
|
Name: c.String("commit.author.name"),
|
|
Email: c.String("commit.author.email"),
|
|
Avatar: c.String("commit.author.avatar"),
|
|
},
|
|
}
|
|
}
|
|
|
|
func previousCommitFlags() []cli.Flag {
|
|
return []cli.Flag{
|
|
&cli.StringFlag{
|
|
Name: "prev.commit.sha",
|
|
Usage: "previous commit SHA",
|
|
Sources: cli.EnvVars(
|
|
"CI_PREV_COMMIT_SHA",
|
|
"DRONE_COMMIT_BEFORE",
|
|
),
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "prev.commit.ref",
|
|
Usage: "previous commit ref",
|
|
Sources: cli.EnvVars(
|
|
"CI_PREV_COMMIT_REF",
|
|
),
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "prev.commit.refspec",
|
|
Usage: "previous commit refspec",
|
|
Sources: cli.EnvVars(
|
|
"CI_PREV_COMMIT_REFSPEC",
|
|
),
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "prev.commit.branch",
|
|
Usage: "previous commit branch",
|
|
Sources: cli.EnvVars(
|
|
"CI_PREV_COMMIT_BRANCH",
|
|
),
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "prev.commit.message",
|
|
Usage: "previous commit message",
|
|
Sources: cli.EnvVars(
|
|
"CI_PREV_COMMIT_MESSAGE",
|
|
),
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "prev.commit.author.name",
|
|
Usage: "previous commit author name",
|
|
Sources: cli.EnvVars(
|
|
"CI_PREV_COMMIT_AUTHOR",
|
|
),
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "prev.commit.author.email",
|
|
Usage: "previous commit author email",
|
|
Sources: cli.EnvVars(
|
|
"CI_PREV_COMMIT_AUTHOR_EMAIL",
|
|
),
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "prev.commit.author.avatar",
|
|
Usage: "previous commit author avatar",
|
|
Sources: cli.EnvVars(
|
|
"CI_PREV_COMMIT_AUTHOR_AVATAR",
|
|
),
|
|
},
|
|
}
|
|
}
|
|
|
|
func previousCommitFromContext(c *cli.Command) Commit {
|
|
return Commit{
|
|
Sha: c.String("prev.commit.sha"),
|
|
Ref: c.String("prev.commit.ref"),
|
|
Refspec: c.String("prev.commit.refspec"),
|
|
Branch: c.String("prev.commit.branch"),
|
|
Message: c.String("prev.commit.message"),
|
|
Author: Author{
|
|
Name: c.String("prev.commit.author.name"),
|
|
Email: c.String("prev.commit.author.email"),
|
|
Avatar: c.String("prev.commit.author.avatar"),
|
|
},
|
|
}
|
|
}
|