shithub: furgit

ref: 94011e3762ca25b8ab3a9b9fe0d7a9e155381477
dir: /receivepack/service/hook_apply.go/

View raw version
package service

func buildHookUpdates(commands []Command) []RefUpdate {
	updates := make([]RefUpdate, 0, len(commands))
	for _, command := range commands {
		updates = append(updates, RefUpdate{
			Name:  command.Name,
			OldID: command.OldID,
			NewID: command.NewID,
		})
	}

	return updates
}

func resultForHookRejection(command Command, message string) CommandResult {
	result := successCommandResult(command)
	result.Error = message

	return result
}

func mergeCommandResults(
	commands []Command,
	rejected map[int]string,
	applied []CommandResult,
	appliedIndices []int,
) []CommandResult {
	out := make([]CommandResult, len(commands))

	for index, message := range rejected {
		out[index] = resultForHookRejection(commands[index], message)
	}

	for i, appliedResult := range applied {
		if i >= len(appliedIndices) {
			break
		}

		out[appliedIndices[i]] = appliedResult
	}

	return out
}