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

This commit is contained in:
Robert Kaussow 2022-05-29 22:18:37 +02:00 committed by GitHub
parent 5ce87cc2ed
commit 24542f9e4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 6 additions and 11 deletions

View File

@ -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.

View File

@ -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",

View File

@ -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

View File

@ -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)