Welcome to mirror list, hosted at ThFree Co, Russian Federation.

utils.js « contribution_events « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8b34506c6ac4c7b067b9eb891defe2c3ae34c09a (plain)
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import events from 'test_fixtures/controller/users/activity.json';
import {
  EVENT_TYPE_APPROVED,
  EVENT_TYPE_EXPIRED,
  EVENT_TYPE_JOINED,
  EVENT_TYPE_LEFT,
  EVENT_TYPE_PUSHED,
  EVENT_TYPE_PRIVATE,
  EVENT_TYPE_MERGED,
  EVENT_TYPE_CLOSED,
  EVENT_TYPE_REOPENED,
  EVENT_TYPE_COMMENTED,
  PUSH_EVENT_REF_TYPE_BRANCH,
  PUSH_EVENT_REF_TYPE_TAG,
  EVENT_TYPE_CREATED,
  TARGET_TYPE_ISSUE,
  TARGET_TYPE_MILESTONE,
  TARGET_TYPE_MERGE_REQUEST,
  TARGET_TYPE_WIKI,
  TARGET_TYPE_DESIGN,
  WORK_ITEM_ISSUE_TYPE_ISSUE,
  WORK_ITEM_ISSUE_TYPE_TASK,
  WORK_ITEM_ISSUE_TYPE_INCIDENT,
  RESOURCE_PARENT_TYPE_PROJECT,
} from '~/contribution_events/constants';

import {
  ISSUE_NOTEABLE_TYPE,
  MERGE_REQUEST_NOTEABLE_TYPE,
  SNIPPET_NOTEABLE_TYPE,
  DESIGN_NOTEABLE_TYPE,
  COMMIT_NOTEABLE_TYPE,
} from '~/notes/constants';

const findEventByAction = (action) => () => events.find((event) => event.action === action);
const findEventByActionAndTargetType = (action, targetType) => () =>
  events.find((event) => event.action === action && event.target?.type === targetType);
const findEventByActionAndIssueType = (action, issueType) => () =>
  events.find((event) => event.action === action && event.target.issue_type === issueType);

export const eventApproved = findEventByAction(EVENT_TYPE_APPROVED);

export const eventExpired = findEventByAction(EVENT_TYPE_EXPIRED);

export const eventJoined = findEventByAction(EVENT_TYPE_JOINED);

export const eventLeft = findEventByAction(EVENT_TYPE_LEFT);

export const eventMerged = findEventByAction(EVENT_TYPE_MERGED);

const findPushEvent = ({
  isNew = false,
  isRemoved = false,
  refType = PUSH_EVENT_REF_TYPE_BRANCH,
  commitCount = 1,
} = {}) => () =>
  events.find(
    ({ action, ref, commit }) =>
      action === EVENT_TYPE_PUSHED &&
      ref.is_new === isNew &&
      ref.is_removed === isRemoved &&
      ref.type === refType &&
      commit.count === commitCount,
  );

export const eventPushedNewBranch = findPushEvent({ isNew: true });
export const eventPushedNewTag = findPushEvent({ isNew: true, refType: PUSH_EVENT_REF_TYPE_TAG });
export const eventPushedBranch = findPushEvent();
export const eventPushedTag = findPushEvent({ refType: PUSH_EVENT_REF_TYPE_TAG });
export const eventPushedRemovedBranch = findPushEvent({ isRemoved: true });
export const eventPushedRemovedTag = findPushEvent({
  isRemoved: true,
  refType: PUSH_EVENT_REF_TYPE_TAG,
});
export const eventBulkPushedBranch = findPushEvent({ commitCount: 5 });

export const eventPrivate = () => ({ ...events[0], action: EVENT_TYPE_PRIVATE });

export const eventCreated = findEventByAction(EVENT_TYPE_CREATED);

export const findCreatedEvent = (targetType) =>
  findEventByActionAndTargetType(EVENT_TYPE_CREATED, targetType);
export const findWorkItemCreatedEvent = (issueType) =>
  findEventByActionAndIssueType(EVENT_TYPE_CREATED, issueType);

export const eventProjectCreated = findCreatedEvent(undefined);
export const eventMilestoneCreated = findCreatedEvent(TARGET_TYPE_MILESTONE);
export const eventIssueCreated = findCreatedEvent(TARGET_TYPE_ISSUE);
export const eventMergeRequestCreated = findCreatedEvent(TARGET_TYPE_MERGE_REQUEST);
export const eventWikiPageCreated = findCreatedEvent(TARGET_TYPE_WIKI);
export const eventDesignCreated = findCreatedEvent(TARGET_TYPE_DESIGN);
export const eventTaskCreated = findWorkItemCreatedEvent(WORK_ITEM_ISSUE_TYPE_TASK);
export const eventIncidentCreated = findWorkItemCreatedEvent(WORK_ITEM_ISSUE_TYPE_INCIDENT);

export const eventClosed = findEventByAction(EVENT_TYPE_CLOSED);

export const findClosedEvent = (targetType) =>
  findEventByActionAndTargetType(EVENT_TYPE_CREATED, targetType);
export const findWorkItemClosedEvent = (issueType) =>
  findEventByActionAndIssueType(EVENT_TYPE_CLOSED, issueType);

export const eventMilestoneClosed = findClosedEvent(TARGET_TYPE_MILESTONE);
export const eventIssueClosed = findClosedEvent(TARGET_TYPE_ISSUE);
export const eventMergeRequestClosed = findClosedEvent(TARGET_TYPE_MERGE_REQUEST);
export const eventWikiPageClosed = findClosedEvent(TARGET_TYPE_WIKI);
export const eventDesignClosed = findClosedEvent(TARGET_TYPE_DESIGN);
export const eventTaskClosed = findWorkItemClosedEvent(WORK_ITEM_ISSUE_TYPE_TASK);
export const eventIncidentClosed = findWorkItemClosedEvent(WORK_ITEM_ISSUE_TYPE_INCIDENT);

export const eventReopened = findEventByAction(EVENT_TYPE_REOPENED);

export const findReopenedEvent = (targetType) =>
  findEventByActionAndTargetType(EVENT_TYPE_REOPENED, targetType);
export const findWorkItemReopenedEvent = (issueType) =>
  findEventByActionAndIssueType(EVENT_TYPE_REOPENED, issueType);

export const eventMilestoneReopened = findReopenedEvent(TARGET_TYPE_MILESTONE);
export const eventMergeRequestReopened = findReopenedEvent(TARGET_TYPE_MERGE_REQUEST);
export const eventWikiPageReopened = findReopenedEvent(TARGET_TYPE_WIKI);
export const eventDesignReopened = findReopenedEvent(TARGET_TYPE_DESIGN);
export const eventIssueReopened = findWorkItemReopenedEvent(WORK_ITEM_ISSUE_TYPE_ISSUE);
export const eventTaskReopened = findWorkItemReopenedEvent(WORK_ITEM_ISSUE_TYPE_TASK);
export const eventIncidentReopened = findWorkItemReopenedEvent(WORK_ITEM_ISSUE_TYPE_INCIDENT);

export const eventCommented = findEventByAction(EVENT_TYPE_COMMENTED);

const findEventByActionAndNoteableType = (action, noteableType) => () =>
  events.find((event) => event.action === action && event.noteable?.type === noteableType);
export const findCommentedEvent = (noteableType) =>
  findEventByActionAndNoteableType(EVENT_TYPE_COMMENTED, noteableType);
export const findCommentedSnippet = (resourceParentType) => () =>
  events.find(
    (event) =>
      event.action === EVENT_TYPE_COMMENTED &&
      event.noteable?.type === SNIPPET_NOTEABLE_TYPE &&
      event.resource_parent?.type === resourceParentType,
  );

export const eventCommentedIssue = findCommentedEvent(ISSUE_NOTEABLE_TYPE);
export const eventCommentedMergeRequest = findCommentedEvent(MERGE_REQUEST_NOTEABLE_TYPE);
export const eventCommentedSnippet = findCommentedEvent(SNIPPET_NOTEABLE_TYPE);
export const eventCommentedProjectSnippet = findCommentedSnippet(RESOURCE_PARENT_TYPE_PROJECT);
export const eventCommentedPersonalSnippet = findCommentedSnippet(null);
export const eventCommentedDesign = findCommentedEvent(DESIGN_NOTEABLE_TYPE);
// Fixtures do not work for commits because they are not written to the database.
// Manually creating a commented commit event as a workaround.
export const eventCommentedCommit = () => ({
  ...eventCommented(),
  noteable: {
    type: COMMIT_NOTEABLE_TYPE,
    reference_link_text: '83c6aa31',
    web_url: 'http://localhost/group3/project-1/-/commit/83c6aa31482b9076531ed3a880e75627fd6b335c',
    first_line_in_markdown: '\u003cp\u003eMy title 9\u003c/p\u003e',
  },
});