code.gitea.io/gitea@v1.21.7/routers/api/v1/org/hook.go (about)

     1  // Copyright 2016 The Gitea Authors. All rights reserved.
     2  // SPDX-License-Identifier: MIT
     3  
     4  package org
     5  
     6  import (
     7  	"net/http"
     8  
     9  	"code.gitea.io/gitea/modules/context"
    10  	api "code.gitea.io/gitea/modules/structs"
    11  	"code.gitea.io/gitea/modules/web"
    12  	"code.gitea.io/gitea/routers/api/v1/utils"
    13  	webhook_service "code.gitea.io/gitea/services/webhook"
    14  )
    15  
    16  // ListHooks list an organziation's webhooks
    17  func ListHooks(ctx *context.APIContext) {
    18  	// swagger:operation GET /orgs/{org}/hooks organization orgListHooks
    19  	// ---
    20  	// summary: List an organization's webhooks
    21  	// produces:
    22  	// - application/json
    23  	// parameters:
    24  	// - name: org
    25  	//   in: path
    26  	//   description: name of the organization
    27  	//   type: string
    28  	//   required: true
    29  	// - name: page
    30  	//   in: query
    31  	//   description: page number of results to return (1-based)
    32  	//   type: integer
    33  	// - name: limit
    34  	//   in: query
    35  	//   description: page size of results
    36  	//   type: integer
    37  	// responses:
    38  	//   "200":
    39  	//     "$ref": "#/responses/HookList"
    40  	//   "404":
    41  	//     "$ref": "#/responses/notFound"
    42  
    43  	utils.ListOwnerHooks(
    44  		ctx,
    45  		ctx.ContextUser,
    46  	)
    47  }
    48  
    49  // GetHook get an organization's hook by id
    50  func GetHook(ctx *context.APIContext) {
    51  	// swagger:operation GET /orgs/{org}/hooks/{id} organization orgGetHook
    52  	// ---
    53  	// summary: Get a hook
    54  	// produces:
    55  	// - application/json
    56  	// parameters:
    57  	// - name: org
    58  	//   in: path
    59  	//   description: name of the organization
    60  	//   type: string
    61  	//   required: true
    62  	// - name: id
    63  	//   in: path
    64  	//   description: id of the hook to get
    65  	//   type: integer
    66  	//   format: int64
    67  	//   required: true
    68  	// responses:
    69  	//   "200":
    70  	//     "$ref": "#/responses/Hook"
    71  	//   "404":
    72  	//     "$ref": "#/responses/notFound"
    73  
    74  	hook, err := utils.GetOwnerHook(ctx, ctx.ContextUser.ID, ctx.ParamsInt64("id"))
    75  	if err != nil {
    76  		return
    77  	}
    78  
    79  	apiHook, err := webhook_service.ToHook(ctx.ContextUser.HomeLink(), hook)
    80  	if err != nil {
    81  		ctx.InternalServerError(err)
    82  		return
    83  	}
    84  	ctx.JSON(http.StatusOK, apiHook)
    85  }
    86  
    87  // CreateHook create a hook for an organization
    88  func CreateHook(ctx *context.APIContext) {
    89  	// swagger:operation POST /orgs/{org}/hooks organization orgCreateHook
    90  	// ---
    91  	// summary: Create a hook
    92  	// consumes:
    93  	// - application/json
    94  	// produces:
    95  	// - application/json
    96  	// parameters:
    97  	// - name: org
    98  	//   in: path
    99  	//   description: name of the organization
   100  	//   type: string
   101  	//   required: true
   102  	// - name: body
   103  	//   in: body
   104  	//   required: true
   105  	//   schema:
   106  	//     "$ref": "#/definitions/CreateHookOption"
   107  	// responses:
   108  	//   "201":
   109  	//     "$ref": "#/responses/Hook"
   110  	//   "404":
   111  	//     "$ref": "#/responses/notFound"
   112  
   113  	utils.AddOwnerHook(
   114  		ctx,
   115  		ctx.ContextUser,
   116  		web.GetForm(ctx).(*api.CreateHookOption),
   117  	)
   118  }
   119  
   120  // EditHook modify a hook of an organization
   121  func EditHook(ctx *context.APIContext) {
   122  	// swagger:operation PATCH /orgs/{org}/hooks/{id} organization orgEditHook
   123  	// ---
   124  	// summary: Update a hook
   125  	// consumes:
   126  	// - application/json
   127  	// produces:
   128  	// - application/json
   129  	// parameters:
   130  	// - name: org
   131  	//   in: path
   132  	//   description: name of the organization
   133  	//   type: string
   134  	//   required: true
   135  	// - name: id
   136  	//   in: path
   137  	//   description: id of the hook to update
   138  	//   type: integer
   139  	//   format: int64
   140  	//   required: true
   141  	// - name: body
   142  	//   in: body
   143  	//   schema:
   144  	//     "$ref": "#/definitions/EditHookOption"
   145  	// responses:
   146  	//   "200":
   147  	//     "$ref": "#/responses/Hook"
   148  	//   "404":
   149  	//     "$ref": "#/responses/notFound"
   150  
   151  	utils.EditOwnerHook(
   152  		ctx,
   153  		ctx.ContextUser,
   154  		web.GetForm(ctx).(*api.EditHookOption),
   155  		ctx.ParamsInt64("id"),
   156  	)
   157  }
   158  
   159  // DeleteHook delete a hook of an organization
   160  func DeleteHook(ctx *context.APIContext) {
   161  	// swagger:operation DELETE /orgs/{org}/hooks/{id} organization orgDeleteHook
   162  	// ---
   163  	// summary: Delete a hook
   164  	// produces:
   165  	// - application/json
   166  	// parameters:
   167  	// - name: org
   168  	//   in: path
   169  	//   description: name of the organization
   170  	//   type: string
   171  	//   required: true
   172  	// - name: id
   173  	//   in: path
   174  	//   description: id of the hook to delete
   175  	//   type: integer
   176  	//   format: int64
   177  	//   required: true
   178  	// responses:
   179  	//   "204":
   180  	//     "$ref": "#/responses/empty"
   181  	//   "404":
   182  	//     "$ref": "#/responses/notFound"
   183  
   184  	utils.DeleteOwnerHook(
   185  		ctx,
   186  		ctx.ContextUser,
   187  		ctx.ParamsInt64("id"),
   188  	)
   189  }