Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use enums for the action field in GitHub Webhooks #3127

Open
prnvbn opened this issue Apr 11, 2024 · 4 comments
Open

Use enums for the action field in GitHub Webhooks #3127

prnvbn opened this issue Apr 11, 2024 · 4 comments

Comments

@prnvbn
Copy link
Contributor

prnvbn commented Apr 11, 2024

Issue Description:

Many GitHub webhooks contain the action field, which is enumerated. For example, in the GitHub documentation for webhook payloads and events, the check_run event includes an action property that can take on values such as "completed", "created", "requested_action", and "rerequested". However, in the library, these fields are currently represented as free-form strings. In my opinion, making these enums would be more user-friendly.

Proposed Solution

A rudimentary example of how this can be done is as follows (go play ground link)

package main

import (
	"encoding/json"
	"fmt"
)

type ChecRunAction string

const (
	CheckRunCreated         ChecRunAction = "created"
	CheckRunRequested       ChecRunAction = "requested"
	CheckRunRerequested     ChecRunAction = "rerequested"
	CheckRunRequestedAction ChecRunAction = "requested_action"
)

func main() {
	jsonStr := `{"hi": "created"}`

	var v struct {
		A ChecRunAction `json:"hi"`
	}
	json.Unmarshal([]byte(jsonStr), &v)
	fmt.Println(v)
}
@prnvbn
Copy link
Contributor Author

prnvbn commented Apr 11, 2024

If you agree, I can make this change

@gmlewis
Copy link
Collaborator

gmlewis commented Apr 11, 2024

That seems safe to me.

@prnvbn
Copy link
Contributor Author

prnvbn commented Apr 12, 2024

nice, will send a PR your way!

@prnvbn
Copy link
Contributor Author

prnvbn commented Apr 21, 2024

@gmlewis, please could you review the PR: #3136?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants