-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle different workflow input types.
- Loading branch information
1 parent
1c8f8e5
commit 7e6da2e
Showing
5 changed files
with
220 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package environment | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/chrisgavin/gh-dispatch/internal/client" | ||
"github.com/cli/go-gh/pkg/api" | ||
"github.com/cli/go-gh/pkg/repository" | ||
"github.com/pkg/errors" | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
type Environment struct { | ||
Name string `json:"name"` | ||
} | ||
|
||
type Environments struct { | ||
Environments []Environment `json:"environments"` | ||
} | ||
|
||
func ListEnvironments(repository repository.Repository) ([]string, error) { | ||
client, err := client.NewClient(repository.Host()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
environments := Environments{} | ||
if err := client.Get(fmt.Sprintf("repos/%s/%s/environments", repository.Owner(), repository.Name()), &environments); err != nil { | ||
if httpError, ok := err.(api.HTTPError); ok { | ||
if httpError.StatusCode == 404 { | ||
log.Warn("Got a 404 when listing environments for the repository. Unfortunately the environments API is a limited to paid organization plans.") | ||
return nil, nil | ||
} | ||
} | ||
return nil, errors.Wrap(err, "Unable to get list of environments.") | ||
} | ||
|
||
names := []string{} | ||
for _, environment := range environments.Environments { | ||
names = append(names, environment.Name) | ||
} | ||
|
||
return names, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters