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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
import httpStatusCodes from '~/lib/utils/http_status';
import { X_TOTAL_HEADER } from '../constants';
import * as types from './mutation_types';
export default {
[types.SET_ENABLED_REF_TYPES](state, refTypes) {
state.enabledRefTypes = refTypes;
},
[types.SET_PROJECT_ID](state, projectId) {
state.projectId = projectId;
},
[types.SET_SELECTED_REF](state, selectedRef) {
state.selectedRef = selectedRef;
},
[types.SET_QUERY](state, query) {
state.query = query;
},
[types.REQUEST_START](state) {
state.requestCount += 1;
},
[types.REQUEST_FINISH](state) {
state.requestCount -= 1;
},
[types.RECEIVE_BRANCHES_SUCCESS](state, response) {
state.matches.branches = {
list: convertObjectPropsToCamelCase(response.data).map((b) => ({
name: b.name,
default: b.default,
})),
totalCount: parseInt(response.headers[X_TOTAL_HEADER], 10),
error: null,
};
},
[types.RECEIVE_BRANCHES_ERROR](state, error) {
state.matches.branches = {
list: [],
totalCount: 0,
error,
};
},
[types.RECEIVE_TAGS_SUCCESS](state, response) {
state.matches.tags = {
list: convertObjectPropsToCamelCase(response.data).map((b) => ({
name: b.name,
})),
totalCount: parseInt(response.headers[X_TOTAL_HEADER], 10),
error: null,
};
},
[types.RECEIVE_TAGS_ERROR](state, error) {
state.matches.tags = {
list: [],
totalCount: 0,
error,
};
},
[types.RECEIVE_COMMITS_SUCCESS](state, response) {
const commit = convertObjectPropsToCamelCase(response.data);
state.matches.commits = {
list: [
{
name: commit.shortId,
value: commit.id,
subtitle: commit.title,
},
],
totalCount: 1,
error: null,
};
},
[types.RECEIVE_COMMITS_ERROR](state, error) {
state.matches.commits = {
list: [],
totalCount: 0,
// 404's are expected when the search query doesn't match any commits
// and shouldn't be treated as an actual error
error: error.response?.status !== httpStatusCodes.NOT_FOUND ? error : null,
};
},
[types.RESET_COMMIT_MATCHES](state) {
state.matches.commits = {
list: [],
totalCount: 0,
error: null,
};
},
};
|