aboutsummaryrefslogtreecommitdiff
path: root/receivepack/service/hook_apply.go
blob: 5bd8f596d50fdd2a5db2f63046219c77cdd16fe2 (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
32
33
34
35
36
37
38
39
40
41
42
43
44
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
}