Skip to content

Commit 3fa316d

Browse files
committed
wip: get basic GH API call stuff working
1 parent 9f03579 commit 3fa316d

File tree

3 files changed

+24
-19
lines changed

3 files changed

+24
-19
lines changed

cmd/github/github.go

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -149,25 +149,28 @@ func (s OrgStatus) String() string {
149149
}
150150

151151
// GetUserOrgStatus takes a GitHub username, and checks the GitHub API to see
152-
// whether that member is part of the Coder organization
153-
func (gc *Client) GetUserOrgStatus(org string, username string) (OrgStatus, error) {
152+
// whether that member is part of the provided organization
153+
func (gc *Client) GetUserOrgStatus(orgName string, username string) (OrgStatus, error) {
154154
// This API endpoint is really annoying, because it's able to produce false
155-
// negatives. Any user can be a public member of Coder, a private member of
156-
// Coder, or a non-member.
155+
// negatives. Any user can be:
156+
// 1. A public member of an organization
157+
// 2. A private member of an organization
158+
// 3. Not a member of an organization
157159
//
158160
// So if the function returns status 200, you can always trust that. But if
159161
// it returns any 400 code, that could indicate a few things:
160-
// 1. The user being checked is not part of the organization, but the user
161-
// associated with the token is.
162-
// 2. The user being checked is a member of the organization, but their
163-
// status is private, and the token being used to check belongs to a user
164-
// who is not part of the Coder organization.
162+
// 1. The user associated with the token is a member of the organization,
163+
// and the user being checked is not.
164+
// 2. The user associated with the token is NOT a member of the
165+
// organization, and the member being checked is a private member. The
166+
// token user will have no way to view the private member's status.
165167
// 3. Neither the user being checked nor the user associated with the token
166-
// are members of the organization
168+
// are members of the organization.
167169
//
168-
// The best option is to make sure that the token being used belongs to a
169-
// member of the Coder organization
170-
req, err := http.NewRequest("GET", fmt.Sprintf("%sorgs/%s/%s", gc.baseURL, org, username), nil)
170+
// The best option to avoid false positives is to make sure that the token
171+
// being used belongs to a member of the organization being checked.
172+
url := fmt.Sprintf("%sorgs/%s/members/%s", gc.baseURL, orgName, username)
173+
req, err := http.NewRequest("GET", url, nil)
171174
if err != nil {
172175
return OrgStatusIndeterminate, err
173176
}

cmd/readmevalidation/contributors.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ func aggregateContributorReadmeFiles() ([]readme, error) {
405405
return allReadmeFiles, nil
406406
}
407407

408-
func validateRelativeUrls(
408+
func validateContributorRelativeUrls(
409409
contributors map[string]contributorProfile,
410410
) error {
411411
// This function only validates relative avatar URLs for now, but it can be

cmd/readmevalidation/main.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
)
1616

1717
func main() {
18+
// Do basic setup
1819
log.Println("Beginning README file validation")
1920
err := godotenv.Load()
2021
if err != nil {
@@ -30,6 +31,8 @@ func main() {
3031
}
3132
log.Printf("Using branch %q for validation comparison", baseRef)
3233

34+
// Retrieve data necessary from the GitHub API to help determine whether
35+
// certain field changes are allowed
3336
log.Printf("Using GitHub API to determine what fields can be set by user %q\n", actorUsername)
3437
client, err := github.NewClient()
3538
if err != nil {
@@ -49,28 +52,27 @@ func main() {
4952
if err != nil {
5053
log.Panic(err)
5154
}
55+
} else {
56+
log.Println("Provided API token does not belong to a Coder employee. Some README validation steps will be skipped compared to when they run in CI.")
5257
}
53-
5458
fmt.Printf("actor %q is %s\n", actorUsername, actorOrgStatus.String())
5559

5660
log.Println("Starting README validation")
61+
5762
allReadmeFiles, err := aggregateContributorReadmeFiles()
5863
if err != nil {
5964
log.Panic(err)
6065
}
61-
6266
log.Printf("Processing %d README files\n", len(allReadmeFiles))
6367
contributors, err := parseContributorFiles(allReadmeFiles)
6468
log.Printf("Processed %d README files as valid contributor profiles", len(contributors))
6569
if err != nil {
6670
log.Panic(err)
6771
}
68-
69-
err = validateRelativeUrls(contributors)
72+
err = validateContributorRelativeUrls(contributors)
7073
if err != nil {
7174
log.Panic(err)
7275
}
7376
log.Println("All relative URLs for READMEs are valid")
74-
7577
log.Printf("Processed all READMEs in the %q directory\n", rootRegistryPath)
7678
}

0 commit comments

Comments
 (0)