2016-03-08 23:05:22 +01:00
|
|
|
package github
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/helper/schema"
|
|
|
|
)
|
|
|
|
|
2017-03-12 15:05:18 +01:00
|
|
|
const (
|
|
|
|
// https://developer.github.com/guides/traversing-with-pagination/#basics-of-pagination
|
|
|
|
maxPerPage = 100
|
|
|
|
)
|
|
|
|
|
2016-03-08 23:05:22 +01:00
|
|
|
func toGithubID(id string) int {
|
|
|
|
githubID, _ := strconv.Atoi(id)
|
|
|
|
return githubID
|
|
|
|
}
|
|
|
|
|
|
|
|
func fromGithubID(id *int) string {
|
|
|
|
return strconv.Itoa(*id)
|
|
|
|
}
|
|
|
|
|
2016-04-11 14:09:25 +02:00
|
|
|
func validateValueFunc(values []string) schema.SchemaValidateFunc {
|
2016-03-08 23:05:22 +01:00
|
|
|
return func(v interface{}, k string) (we []string, errors []error) {
|
|
|
|
value := v.(string)
|
|
|
|
valid := false
|
2016-04-11 14:09:25 +02:00
|
|
|
for _, role := range values {
|
2016-03-08 23:05:22 +01:00
|
|
|
if value == role {
|
|
|
|
valid = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if !valid {
|
2016-04-11 14:09:25 +02:00
|
|
|
errors = append(errors, fmt.Errorf("%s is an invalid value for argument %s", value, k))
|
2016-03-08 23:05:22 +01:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// return the pieces of id `a:b` as a, b
|
|
|
|
func parseTwoPartID(id string) (string, string) {
|
|
|
|
parts := strings.SplitN(id, ":", 2)
|
|
|
|
return parts[0], parts[1]
|
|
|
|
}
|
|
|
|
|
|
|
|
// format the strings into an id `a:b`
|
|
|
|
func buildTwoPartID(a, b *string) string {
|
|
|
|
return fmt.Sprintf("%s:%s", *a, *b)
|
|
|
|
}
|