Repository: go-gitea/gitea
File: services/lfs/locks.go (Go)

Code before:
			Message: "You must have push access to create locks",
		})
		return
	}

	ctx.Resp.Header().Set("Content-Type", lfs_module.MediaType)

	var req api.LFSLockRequest
	bodyReader := ctx.Req.Body
	defer bodyReader.Close()

	dec := json.NewDecoder(bodyReader)
	if err := dec.Decode(&req); err != nil {
		log.Warn("Failed to decode lock request as json. Error: %v", err)
		writeStatus(ctx, http.StatusBadRequest)
		return
	}

	var lockCtx go_context.Context = ctx
	// Pass Actions Task ID in context if creating lock using Actions Job Token
	if ctx.Data["IsActionsToken"] == true {
		taskID := ctx.Data["ActionsTaskID"].(int64)
		lockCtx = go_context.WithValue(lockCtx, access_model.ActionsTaskIDKey, taskID)
	}

	lock, err := git_model.CreateLFSLock(lockCtx, repository, &git_model.LFSLock{
		Path:    req.Path,
		OwnerID: ctx.Doer.ID,
	})
	if err != nil {
		if git_model.IsErrLFSLockAlreadyExist(err) {
			ctx.JSON(http.StatusConflict, api.LFSLockError{
				Lock:    convert.ToLFSLock(ctx, lock),
				Message: "already created lock",
			})
			return
		}
		if git_model.IsErrLFSUnauthorizedAction(err) {
			ctx.Resp.Header().Set("WWW-Authenticate", `Basic realm="gitea-lfs"`)
			ctx.JSON(http.StatusUnauthorized, api.LFSLockError{
				Message: "You must have push access to create locks : " + err.Error(),
			})
			return
		}
		log.Error("Unable to CreateLFSLock in repository %-v at %s for user %-v: Error: %v", repository, req.Path, ctx.Doer, err)
		ctx.JSON(http.StatusInternalServerError, api.LFSLockError{
			Message: "internal server error : Internal Server Error",
		})
		return
	}
	ctx.JSON(http.StatusCreated, api.LFSLockResponse{Lock: convert.ToLFSLock(ctx, lock)})

Review comment (refactor):
I didn't have any better idea, git_model has no access to our context_service

Maybe replace ctx.Data["ActionsTaskID"] = taskid. everywhere to use context value of key access_model.ActionsTaskIDKey and remove "IsActionsToken" that duplicates an available taskID everywhere this is being used

Code after:
		return
	}

	ctx.Resp.Header().Set("Content-Type", lfs_module.MediaType)

	var req api.LFSLockRequest
	bodyReader := ctx.Req.Body
	defer bodyReader.Close()

	dec := json.NewDecoder(bodyReader)
	if err := dec.Decode(&req); err != nil {
		log.Warn("Failed to decode lock request as json. Error: %v", err)
		writeStatus(ctx, http.StatusBadRequest)
		return
	}

	lock, err := git_model.CreateLFSLock(ctx, repository, &git_model.LFSLock{
		Path:    req.Path,
		OwnerID: ctx.Doer.ID,
	})
	if err != nil {
		if git_model.IsErrLFSLockAlreadyExist(err) {
			ctx.JSON(http.StatusConflict, api.LFSLockError{
				Lock:    convert.ToLFSLock(ctx, lock),
				Message: "already created lock",
			})
			return
		}
		log.Error("Unable to CreateLFSLock in repository %-v at %s for user %-v: Error: %v", repository, req.Path, ctx.Doer, err)
		ctx.JSON(http.StatusInternalServerError, api.LFSLockError{
			Message: "internal server error : Internal Server Error",
		})
		return
	}
	ctx.JSON(http.StatusCreated, api.LFSLockResponse{Lock: convert.ToLFSLock(ctx, lock)})
}

// VerifyLockHandler list locks for verification
func VerifyLockHandler(ctx *context.Context) {
	userName := ctx.PathParam("username")
	repoName := strings.TrimSuffix(ctx.PathParam("reponame"), ".git")
	authorization := ctx.Req.Header.Get("Authorization")

	repository, err := repo_model.GetRepositoryByOwnerAndName(ctx, userName, repoName)
	if err != nil {
		log.Error("Unable to get repository: %s/%s Error: %v", userName, repoName, err)
		ctx.Resp.Header().Set("WWW-Authenticate", `Basic realm="gitea-lfs"`)
		ctx.JSON(http.StatusUnauthorized, api.LFSLockError{
			Message: "You must have push access to verify locks",
		})
		return