google / google/go-github

Use enums for the action field in GitHub Webhooks

Aperta
#3,127 4 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Go
Stelle
11.3k
Fork
2.5k
Merge medio
1g 20h
PR unite (30g)
53

Descrizione

## Issue Description:

Many GitHub webhooks contain the action field, which is enumerated. For example, in the [GitHub documentation for webhook payloads and events](https://docs.github.com/en/webhooks/webhook-events-and-payloads#check_run), 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](https://goplay.tools/snippet/gBqRSMGO0Px))

```go
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)
}

```

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia inventariando i tipi di payload dei webhook in go-github e confrontando ogni campo action con la documentazione di GitHub webhook events and payloads, iniziando da check_run. Definisci l’ambito completo degli eventi e l’approccio per la denominazione degli enum prima di modificare i tipi; il lavoro è completo quando i campi action selezionati usano costanti tipizzate preservando i valori JSON documentati.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
go
Ambito
api
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
30/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.