aboutsummaryrefslogtreecommitdiff
path: root/network/receivepack/service/hook_apply.go
blob: 97d25009a42b3bdf1088ababcece9ae7a0dc299d (about) (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package service

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
}