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

Autofix/01 j0 hq0 a7 gg1 stvt9074 r18 tmz #199

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/workflows/ci-require-labels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Require labels to be added to a PR before merging
# This is configured as a branch protection setting
name: CI Require Labels
on:
pull_request:
types: [opened, labeled, unlabeled, synchronize]
merge_group:
run-name: CI Require Labels ${{ github.sha }} by @${{ github.actor }}
jobs:
require-labels:
if: ${{ github.event_name == 'pull_request' }}
runs-on: ubuntu-latest
outputs:
status: ${{ steps.require-labels.outputs.status }}
steps:
- uses: actions/checkout@v3
- name: Require Labels
id: require-labels
uses: nullify-platform/github-actions/actions/require-labels@main
50 changes: 50 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Create Release
on:
workflow_dispatch:
inputs:
releaseType:
description: Create a draft release
required: true
type: boolean
default: true
push:
branches:
- main
concurrency:
group: release
cancel-in-progress: false
run-name: Release ${{ github.sha }} by @${{ github.actor }}
permissions:
contents: write
id-token: write
pull-requests: read
jobs:
get-version:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.get-version.outputs.version }}
steps:
- uses: actions/checkout@v3
- name: Get Release Version
id: get-version
uses: nullify-platform/github-actions/actions/release-version@main
- run: |
echo "config-file-parser @ ${{ github.sha }}" >> $GITHUB_STEP_SUMMARY
echo "VERSION: ${{ steps.get-version.outputs.version }}" >> $GITHUB_STEP_SUMMARY
echo "SHORT_SHA: $(git rev-parse --short HEAD)" >> $GITHUB_STEP_SUMMARY
release:
if: ${{ needs.get-version.outputs.version != 'undefined' || (github.event_name == 'workflow_dispatch' && needs.get-version.outputs.version != 'undefined') }}
runs-on: ubuntu-latest
needs: [ get-version ]
steps:
- uses: actions/checkout@v3
- name: Generate Release Tag
run: echo "RELEASE_TAG=v${{ needs.get-version.outputs.version }}" >> $GITHUB_ENV
- name: Generate Release
uses: softprops/action-gh-release@v1
with:
draft: false
generate_release_notes: true
append_body: true
tag_name: ${{ env.RELEASE_TAG }}
token: ${{ secrets.GITHUB_TOKEN }}
22 changes: 18 additions & 4 deletions _examples/single-handler/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package main

import (
"fmt"

"net/http"
"time"

"github.com/go-playground/webhooks/v6/github"
)
Expand All @@ -15,11 +15,12 @@ const (
func main() {
hook, _ := github.New(github.Options.Secret("MyGitHubSuperSecretSecrect...?"))

http.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
mux := http.NewServeMux()
mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
payload, err := hook.Parse(r, github.ReleaseEvent, github.PullRequestEvent)
if err != nil {
if err == github.ErrEventNotFound {
// ok event wasn;t one of the ones asked to be parsed
// ok event wasn't one of the ones asked to be parsed
}
}
switch payload.(type) {
Expand All @@ -35,5 +36,18 @@ func main() {
fmt.Printf("%+v", pullRequest)
}
})
http.ListenAndServe(":3000", nil)

server := &http.Server{
Addr: ":3000",
Handler: mux,
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
IdleTimeout: 120 * time.Second,
}

fmt.Println("Server is starting on port 3000...")
if err := server.ListenAndServe(); err != nil && err != http.ErrServerClosed {
fmt.Printf("Error starting server: %s
", err)
}
}
5 changes: 5 additions & 0 deletions azuredevops/azuredevops.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const (
GitPullRequestUpdatedEventType Event = "git.pullrequest.updated"
GitPullRequestMergedEventType Event = "git.pullrequest.merged"
GitPushEventType Event = "git.push"
GitPullRequestCommentEventType Event = "ms.vss-code.git-pullrequest-comment-event"
)

// Webhook instance contains all methods needed to process events
Expand Down Expand Up @@ -74,6 +75,10 @@ func (hook Webhook) Parse(r *http.Request, events ...Event) (interface{}, error)
var fpl BuildCompleteEvent
err = json.Unmarshal([]byte(payload), &fpl)
return fpl, err
case GitPullRequestCommentEventType:
var fpl GitPullRequestCommentEvent
err = json.Unmarshal([]byte(payload), &fpl)
return fpl, err
default:
return nil, fmt.Errorf("unknown event %s", pl.EventType)
}
Expand Down
27 changes: 27 additions & 0 deletions azuredevops/payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@ type GitPushEvent struct {
Scope string `json:"scope"`
}

// "ms.vss-code.git-pullrequest-comment-event"

type GitPullRequestCommentEvent struct {
ID string `json:"id"`
EventType Event `json:"eventType"`
PublisherID string `json:"publisherId"`
Scope string `json:"scope"`
Message Message `json:"message"`
Resource PullRequestComment `json:"resource"`
}

// build.complete

type BuildCompleteEvent struct {
Expand Down Expand Up @@ -100,6 +111,22 @@ type PullRequest struct {
URL string `json:"url"`
}

type PullRequestComment struct {
PullRequest PullRequest `json:"pullRequest"`
Comment Comment `json:"comment"`
}

type Comment struct {
ID int `json:"id"`
ParentCommentID int `json:"parentCommentId"`
Content string `json:"content"`
Author User `json:"author"`
PublishedDate Date `json:"publishedDate"`
LastUpdatedDate Date `json:"lastUpdatedDate"`
LastContentUpdatedDate Date `json:"lastContentUpdatedDate"`
CommentType string `json:"commentType"`
}

type Repository struct {
ID string `json:"id"`
Name string `json:"name"`
Expand Down
44 changes: 33 additions & 11 deletions github/payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,17 +216,39 @@ type CheckRunPayload struct {
type CheckSuitePayload struct {
Action string `json:"action"`
CheckSuite struct {
ID int64 `json:"id"`
NodeID string `json:"node_id"`
HeadBranch string `json:"head_branch"`
HeadSHA string `json:"head_sha"`
Status string `json:"status"`
Conclusion string `json:"conclusion"`
URL string `json:"url"`
Before string `json:"before"`
After string `json:"after"`
PullRequests []PullRequestPayload `json:"pull_requests"`
App struct {
ID int64 `json:"id"`
NodeID string `json:"node_id"`
HeadBranch string `json:"head_branch"`
HeadSHA string `json:"head_sha"`
Status string `json:"status"`
Conclusion string `json:"conclusion"`
URL string `json:"url"`
Before string `json:"before"`
After string `json:"after"`
PullRequests []struct {
URL string `json:"url"`
ID int64 `json:"id"`
Number int64 `json:"number"`
Head struct {
Ref string `json:"ref"`
SHA string `json:"sha"`
Repo struct {
ID int64 `json:"id"`
URL string `json:"url"`
Name string `json:"name"`
} `json:"repo"`
} `json:"head"`
Base struct {
Ref string `json:"ref"`
SHA string `json:"sha"`
Repo struct {
ID int64 `json:"id"`
URL string `json:"url"`
Name string `json:"name"`
} `json:"repo"`
} `json:"base"`
} `json:"pull_requests"`
App struct {
ID int64 `json:"id"`
NodeID string `json:"node_id"`
Owner struct {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/go-playground/webhooks/v6
module github.com/nullify-platform/webhooks

go 1.17

Expand Down
Loading
Loading