Browse Source

chore: use required cli flags instead of manual validation (#108)

pull/109/head
Robert Kaussow 4 weeks ago committed by GitHub
parent
commit
24542f9e4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      _docs/data/data.yaml
  2. 2
      cmd/drone-github-comment/config.go
  3. 2
      plugin/comment.go
  4. 7
      plugin/impl.go

6
_docs/data/data.yaml

@ -3,7 +3,7 @@ properties:
api_key:
description: Personal Access token to access the GitHub API.
type: string
required: false
required: true
base_url:
description: API URL. Only need to be changed for GitHub enterprise in most cases
@ -17,9 +17,9 @@ properties:
required: false
message:
description: File or string that contains the comment text.
description: Path to file or string that contains the comment text.
type: string
required: false
required: true
update:
description: Enables update of an existing comment that matches the key.

2
cmd/drone-github-comment/config.go

@ -14,6 +14,7 @@ func settingsFlags(settings *plugin.Settings, category string) []cli.Flag {
Usage: "personal access token access github api",
Destination: &settings.APIKey,
Category: category,
Required: true,
},
&cli.StringFlag{
Name: "base-url",
@ -36,6 +37,7 @@ func settingsFlags(settings *plugin.Settings, category string) []cli.Flag {
Usage: "file or string that holds the comment text",
Destination: &settings.Message,
Category: category,
Required: true,
},
&cli.BoolFlag{
Name: "update",

2
plugin/comment.go

@ -47,7 +47,7 @@ func (cc *commentClient) issueComment() error {
}
if err != nil {
return fmt.Errorf("failed to add or update comment: %w", err)
return err
}
return nil

7
plugin/impl.go

@ -34,13 +34,6 @@ func (p *Plugin) Validate() error {
return fmt.Errorf("github comment plugin is only available for pull requests")
}
if p.settings.APIKey == "" {
return fmt.Errorf("no api key provided")
}
if p.settings.Message == "" {
return fmt.Errorf("no message provides")
}
if p.settings.Message != "" {
if p.settings.Message, p.settings.IsFile, err = readStringOrFile(p.settings.Message); err != nil {
return fmt.Errorf("error while reading %s: %w", p.settings.Message, err)

Loading…
Cancel
Save