code.gitea.io/gitea@v1.21.7/routers/api/v1/misc/gitignore.go (about)

     1  // Copyright 2023 The Gitea Authors. All rights reserved.
     2  // SPDX-License-Identifier: MIT
     3  
     4  package misc
     5  
     6  import (
     7  	"net/http"
     8  
     9  	"code.gitea.io/gitea/modules/context"
    10  	"code.gitea.io/gitea/modules/options"
    11  	repo_module "code.gitea.io/gitea/modules/repository"
    12  	"code.gitea.io/gitea/modules/structs"
    13  	"code.gitea.io/gitea/modules/util"
    14  )
    15  
    16  // Shows a list of all Gitignore templates
    17  func ListGitignoresTemplates(ctx *context.APIContext) {
    18  	// swagger:operation GET /gitignore/templates miscellaneous listGitignoresTemplates
    19  	// ---
    20  	// summary: Returns a list of all gitignore templates
    21  	// produces:
    22  	// - application/json
    23  	// responses:
    24  	//   "200":
    25  	//     "$ref": "#/responses/GitignoreTemplateList"
    26  	ctx.JSON(http.StatusOK, repo_module.Gitignores)
    27  }
    28  
    29  // SHows information about a gitignore template
    30  func GetGitignoreTemplateInfo(ctx *context.APIContext) {
    31  	// swagger:operation GET /gitignore/templates/{name} miscellaneous getGitignoreTemplateInfo
    32  	// ---
    33  	// summary: Returns information about a gitignore template
    34  	// produces:
    35  	// - application/json
    36  	// parameters:
    37  	// - name: name
    38  	//   in: path
    39  	//   description: name of the template
    40  	//   type: string
    41  	//   required: true
    42  	// responses:
    43  	//   "200":
    44  	//     "$ref": "#/responses/GitignoreTemplateInfo"
    45  	//   "404":
    46  	//     "$ref": "#/responses/notFound"
    47  	name := util.PathJoinRelX(ctx.Params("name"))
    48  
    49  	text, err := options.Gitignore(name)
    50  	if err != nil {
    51  		ctx.NotFound()
    52  		return
    53  	}
    54  
    55  	ctx.JSON(http.StatusOK, &structs.GitignoreTemplateInfo{Name: name, Source: string(text)})
    56  }