decap-cms-backend-github 2.15.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,69 @@
1
+ import GraphQLAPI from '../GraphQLAPI';
2
+
3
+ global.fetch = jest.fn().mockRejectedValue(new Error('should not call fetch inside tests'));
4
+
5
+ describe('github GraphQL API', () => {
6
+ beforeEach(() => {
7
+ jest.resetAllMocks();
8
+ });
9
+
10
+ describe('editorialWorkflowGit', () => {
11
+ it('should should flatten nested tree into a list of files', () => {
12
+ const api = new GraphQLAPI({ branch: 'gh-pages', repo: 'owner/my-repo' });
13
+ const entries = [
14
+ {
15
+ name: 'post-1.md',
16
+ sha: 'sha-1',
17
+ type: 'blob',
18
+ blob: { size: 1 },
19
+ },
20
+ {
21
+ name: 'post-2.md',
22
+ sha: 'sha-2',
23
+ type: 'blob',
24
+ blob: { size: 2 },
25
+ },
26
+ {
27
+ name: '2019',
28
+ sha: 'dir-sha',
29
+ type: 'tree',
30
+ object: {
31
+ entries: [
32
+ {
33
+ name: 'nested-post.md',
34
+ sha: 'nested-post-sha',
35
+ type: 'blob',
36
+ blob: { size: 3 },
37
+ },
38
+ ],
39
+ },
40
+ },
41
+ ];
42
+ const path = 'posts';
43
+
44
+ expect(api.getAllFiles(entries, path)).toEqual([
45
+ {
46
+ name: 'post-1.md',
47
+ id: 'sha-1',
48
+ type: 'blob',
49
+ size: 1,
50
+ path: 'posts/post-1.md',
51
+ },
52
+ {
53
+ name: 'post-2.md',
54
+ id: 'sha-2',
55
+ type: 'blob',
56
+ size: 2,
57
+ path: 'posts/post-2.md',
58
+ },
59
+ {
60
+ name: 'nested-post.md',
61
+ id: 'nested-post-sha',
62
+ type: 'blob',
63
+ size: 3,
64
+ path: 'posts/2019/nested-post.md',
65
+ },
66
+ ]);
67
+ });
68
+ });
69
+ });
@@ -0,0 +1,361 @@
1
+ import { Cursor, CURSOR_COMPATIBILITY_SYMBOL } from 'decap-cms-lib-util';
2
+
3
+ import GitHubImplementation from '../implementation';
4
+
5
+ jest.spyOn(console, 'error').mockImplementation(() => {});
6
+
7
+ describe('github backend implementation', () => {
8
+ const config = {
9
+ backend: {
10
+ repo: 'owner/repo',
11
+ open_authoring: false,
12
+ api_root: 'https://api.github.com',
13
+ },
14
+ };
15
+
16
+ const createObjectURL = jest.fn();
17
+ global.URL = {
18
+ createObjectURL,
19
+ };
20
+
21
+ createObjectURL.mockReturnValue('displayURL');
22
+
23
+ beforeEach(() => {
24
+ jest.clearAllMocks();
25
+ });
26
+
27
+ describe('forkExists', () => {
28
+ it('should return true when repo is fork and parent matches originRepo', async () => {
29
+ const gitHubImplementation = new GitHubImplementation(config);
30
+ gitHubImplementation.currentUser = jest.fn().mockResolvedValue({ login: 'login' });
31
+
32
+ global.fetch = jest.fn().mockResolvedValue({
33
+ // matching should be case-insensitive
34
+ json: () => ({ fork: true, parent: { full_name: 'OWNER/REPO' } }),
35
+ });
36
+
37
+ await expect(gitHubImplementation.forkExists({ token: 'token' })).resolves.toBe(true);
38
+
39
+ expect(gitHubImplementation.currentUser).toHaveBeenCalledTimes(1);
40
+ expect(gitHubImplementation.currentUser).toHaveBeenCalledWith({ token: 'token' });
41
+ expect(global.fetch).toHaveBeenCalledTimes(1);
42
+ expect(global.fetch).toHaveBeenCalledWith('https://api.github.com/repos/login/repo', {
43
+ method: 'GET',
44
+ headers: {
45
+ Authorization: 'token token',
46
+ },
47
+ signal: expect.any(AbortSignal),
48
+ });
49
+ });
50
+
51
+ it('should return false when repo is not a fork', async () => {
52
+ const gitHubImplementation = new GitHubImplementation(config);
53
+ gitHubImplementation.currentUser = jest.fn().mockResolvedValue({ login: 'login' });
54
+
55
+ global.fetch = jest.fn().mockResolvedValue({
56
+ // matching should be case-insensitive
57
+ json: () => ({ fork: false }),
58
+ });
59
+
60
+ expect.assertions(1);
61
+ await expect(gitHubImplementation.forkExists({ token: 'token' })).resolves.toBe(false);
62
+ });
63
+
64
+ it("should return false when parent doesn't match originRepo", async () => {
65
+ const gitHubImplementation = new GitHubImplementation(config);
66
+ gitHubImplementation.currentUser = jest.fn().mockResolvedValue({ login: 'login' });
67
+
68
+ global.fetch = jest.fn().mockResolvedValue({
69
+ json: () => ({ fork: true, parent: { full_name: 'owner/other_repo' } }),
70
+ });
71
+
72
+ expect.assertions(1);
73
+ await expect(gitHubImplementation.forkExists({ token: 'token' })).resolves.toBe(false);
74
+ });
75
+ });
76
+
77
+ describe('persistMedia', () => {
78
+ const persistFiles = jest.fn();
79
+ const mockAPI = {
80
+ persistFiles,
81
+ };
82
+
83
+ persistFiles.mockImplementation((_, files) => {
84
+ files.forEach((file, index) => {
85
+ file.sha = index;
86
+ });
87
+ });
88
+
89
+ it('should persist media file', async () => {
90
+ const gitHubImplementation = new GitHubImplementation(config);
91
+ gitHubImplementation.api = mockAPI;
92
+
93
+ const mediaFile = {
94
+ fileObj: { size: 100, name: 'image.png' },
95
+ path: '/media/image.png',
96
+ };
97
+
98
+ expect.assertions(5);
99
+ await expect(gitHubImplementation.persistMedia(mediaFile, {})).resolves.toEqual({
100
+ id: 0,
101
+ name: 'image.png',
102
+ size: 100,
103
+ displayURL: 'displayURL',
104
+ path: 'media/image.png',
105
+ });
106
+
107
+ expect(persistFiles).toHaveBeenCalledTimes(1);
108
+ expect(persistFiles).toHaveBeenCalledWith([], [mediaFile], {});
109
+ expect(createObjectURL).toHaveBeenCalledTimes(1);
110
+ expect(createObjectURL).toHaveBeenCalledWith(mediaFile.fileObj);
111
+ });
112
+
113
+ it('should log and throw error on "persistFiles" error', async () => {
114
+ const gitHubImplementation = new GitHubImplementation(config);
115
+ gitHubImplementation.api = mockAPI;
116
+
117
+ const error = new Error('failed to persist files');
118
+ persistFiles.mockRejectedValue(error);
119
+
120
+ const mediaFile = {
121
+ value: 'image.png',
122
+ fileObj: { size: 100 },
123
+ path: '/media/image.png',
124
+ };
125
+
126
+ expect.assertions(5);
127
+ await expect(gitHubImplementation.persistMedia(mediaFile)).rejects.toThrowError(error);
128
+
129
+ expect(persistFiles).toHaveBeenCalledTimes(1);
130
+ expect(createObjectURL).toHaveBeenCalledTimes(0);
131
+ expect(console.error).toHaveBeenCalledTimes(1);
132
+ expect(console.error).toHaveBeenCalledWith(error);
133
+ });
134
+ });
135
+
136
+ describe('unpublishedEntry', () => {
137
+ const generateContentKey = jest.fn();
138
+ const retrieveUnpublishedEntryData = jest.fn();
139
+
140
+ const mockAPI = {
141
+ generateContentKey,
142
+ retrieveUnpublishedEntryData,
143
+ };
144
+
145
+ it('should return unpublished entry data', async () => {
146
+ const gitHubImplementation = new GitHubImplementation(config);
147
+ gitHubImplementation.api = mockAPI;
148
+ gitHubImplementation.loadEntryMediaFiles = jest
149
+ .fn()
150
+ .mockResolvedValue([{ path: 'image.png', id: 'sha' }]);
151
+
152
+ generateContentKey.mockReturnValue('contentKey');
153
+
154
+ const data = {
155
+ collection: 'collection',
156
+ slug: 'slug',
157
+ status: 'draft',
158
+ diffs: [],
159
+ updatedAt: 'updatedAt',
160
+ };
161
+ retrieveUnpublishedEntryData.mockResolvedValue(data);
162
+
163
+ const collection = 'posts';
164
+ const slug = 'slug';
165
+ await expect(gitHubImplementation.unpublishedEntry({ collection, slug })).resolves.toEqual(
166
+ data,
167
+ );
168
+
169
+ expect(generateContentKey).toHaveBeenCalledTimes(1);
170
+ expect(generateContentKey).toHaveBeenCalledWith('posts', 'slug');
171
+
172
+ expect(retrieveUnpublishedEntryData).toHaveBeenCalledTimes(1);
173
+ expect(retrieveUnpublishedEntryData).toHaveBeenCalledWith('contentKey');
174
+ });
175
+ });
176
+
177
+ describe('entriesByFolder', () => {
178
+ const listFiles = jest.fn();
179
+ const readFile = jest.fn();
180
+ const readFileMetadata = jest.fn(() => Promise.resolve({ author: '', updatedOn: '' }));
181
+
182
+ const mockAPI = {
183
+ listFiles,
184
+ readFile,
185
+ readFileMetadata,
186
+ originRepoURL: 'originRepoURL',
187
+ };
188
+
189
+ it('should return entries and cursor', async () => {
190
+ const gitHubImplementation = new GitHubImplementation(config);
191
+ gitHubImplementation.api = mockAPI;
192
+
193
+ const files = [];
194
+ const count = 1501;
195
+ for (let i = 0; i < count; i++) {
196
+ const id = `${i}`.padStart(`${count}`.length, '0');
197
+ files.push({
198
+ id,
199
+ path: `posts/post-${id}.md`,
200
+ });
201
+ }
202
+
203
+ listFiles.mockResolvedValue(files);
204
+ readFile.mockImplementation((path, id) => Promise.resolve(`${id}`));
205
+
206
+ const expectedEntries = files
207
+ .slice(0, 20)
208
+ .map(({ id, path }) => ({ data: id, file: { path, id, author: '', updatedOn: '' } }));
209
+
210
+ const expectedCursor = Cursor.create({
211
+ actions: ['next', 'last'],
212
+ meta: { page: 1, count, pageSize: 20, pageCount: 76 },
213
+ data: { files },
214
+ });
215
+
216
+ expectedEntries[CURSOR_COMPATIBILITY_SYMBOL] = expectedCursor;
217
+
218
+ const result = await gitHubImplementation.entriesByFolder('posts', 'md', 1);
219
+
220
+ expect(result).toEqual(expectedEntries);
221
+ expect(listFiles).toHaveBeenCalledTimes(1);
222
+ expect(listFiles).toHaveBeenCalledWith('posts', { depth: 1, repoURL: 'originRepoURL' });
223
+ expect(readFile).toHaveBeenCalledTimes(20);
224
+ });
225
+ });
226
+
227
+ describe('traverseCursor', () => {
228
+ const listFiles = jest.fn();
229
+ const readFile = jest.fn((path, id) => Promise.resolve(`${id}`));
230
+ const readFileMetadata = jest.fn(() => Promise.resolve({}));
231
+
232
+ const mockAPI = {
233
+ listFiles,
234
+ readFile,
235
+ originRepoURL: 'originRepoURL',
236
+ readFileMetadata,
237
+ };
238
+
239
+ const files = [];
240
+ const count = 1501;
241
+ for (let i = 0; i < count; i++) {
242
+ const id = `${i}`.padStart(`${count}`.length, '0');
243
+ files.push({
244
+ id,
245
+ path: `posts/post-${id}.md`,
246
+ });
247
+ }
248
+
249
+ it('should handle next action', async () => {
250
+ const gitHubImplementation = new GitHubImplementation(config);
251
+ gitHubImplementation.api = mockAPI;
252
+
253
+ const cursor = Cursor.create({
254
+ actions: ['next', 'last'],
255
+ meta: { page: 1, count, pageSize: 20, pageCount: 76 },
256
+ data: { files },
257
+ });
258
+
259
+ const expectedEntries = files
260
+ .slice(20, 40)
261
+ .map(({ id, path }) => ({ data: id, file: { path, id } }));
262
+
263
+ const expectedCursor = Cursor.create({
264
+ actions: ['prev', 'first', 'next', 'last'],
265
+ meta: { page: 2, count, pageSize: 20, pageCount: 76 },
266
+ data: { files },
267
+ });
268
+
269
+ const result = await gitHubImplementation.traverseCursor(cursor, 'next');
270
+
271
+ expect(result).toEqual({
272
+ entries: expectedEntries,
273
+ cursor: expectedCursor,
274
+ });
275
+ });
276
+
277
+ it('should handle prev action', async () => {
278
+ const gitHubImplementation = new GitHubImplementation(config);
279
+ gitHubImplementation.api = mockAPI;
280
+
281
+ const cursor = Cursor.create({
282
+ actions: ['prev', 'first', 'next', 'last'],
283
+ meta: { page: 2, count, pageSize: 20, pageCount: 76 },
284
+ data: { files },
285
+ });
286
+
287
+ const expectedEntries = files
288
+ .slice(0, 20)
289
+ .map(({ id, path }) => ({ data: id, file: { path, id } }));
290
+
291
+ const expectedCursor = Cursor.create({
292
+ actions: ['next', 'last'],
293
+ meta: { page: 1, count, pageSize: 20, pageCount: 76 },
294
+ data: { files },
295
+ });
296
+
297
+ const result = await gitHubImplementation.traverseCursor(cursor, 'prev');
298
+
299
+ expect(result).toEqual({
300
+ entries: expectedEntries,
301
+ cursor: expectedCursor,
302
+ });
303
+ });
304
+
305
+ it('should handle last action', async () => {
306
+ const gitHubImplementation = new GitHubImplementation(config);
307
+ gitHubImplementation.api = mockAPI;
308
+
309
+ const cursor = Cursor.create({
310
+ actions: ['next', 'last'],
311
+ meta: { page: 1, count, pageSize: 20, pageCount: 76 },
312
+ data: { files },
313
+ });
314
+
315
+ const expectedEntries = files
316
+ .slice(1500)
317
+ .map(({ id, path }) => ({ data: id, file: { path, id } }));
318
+
319
+ const expectedCursor = Cursor.create({
320
+ actions: ['prev', 'first'],
321
+ meta: { page: 76, count, pageSize: 20, pageCount: 76 },
322
+ data: { files },
323
+ });
324
+
325
+ const result = await gitHubImplementation.traverseCursor(cursor, 'last');
326
+
327
+ expect(result).toEqual({
328
+ entries: expectedEntries,
329
+ cursor: expectedCursor,
330
+ });
331
+ });
332
+
333
+ it('should handle first action', async () => {
334
+ const gitHubImplementation = new GitHubImplementation(config);
335
+ gitHubImplementation.api = mockAPI;
336
+
337
+ const cursor = Cursor.create({
338
+ actions: ['prev', 'first'],
339
+ meta: { page: 76, count, pageSize: 20, pageCount: 76 },
340
+ data: { files },
341
+ });
342
+
343
+ const expectedEntries = files
344
+ .slice(0, 20)
345
+ .map(({ id, path }) => ({ data: id, file: { path, id } }));
346
+
347
+ const expectedCursor = Cursor.create({
348
+ actions: ['next', 'last'],
349
+ meta: { page: 1, count, pageSize: 20, pageCount: 76 },
350
+ data: { files },
351
+ });
352
+
353
+ const result = await gitHubImplementation.traverseCursor(cursor, 'first');
354
+
355
+ expect(result).toEqual({
356
+ entries: expectedEntries,
357
+ cursor: expectedCursor,
358
+ });
359
+ });
360
+ });
361
+ });
@@ -0,0 +1 @@
1
+ module.exports = {"__schema":{"types":[{"kind":"INTERFACE","name":"Node","possibleTypes":[{"name":"AddedToProjectEvent"},{"name":"App"},{"name":"AssignedEvent"},{"name":"BaseRefChangedEvent"},{"name":"BaseRefForcePushedEvent"},{"name":"Blob"},{"name":"Bot"},{"name":"BranchProtectionRule"},{"name":"ClosedEvent"},{"name":"CodeOfConduct"},{"name":"CommentDeletedEvent"},{"name":"Commit"},{"name":"CommitComment"},{"name":"CommitCommentThread"},{"name":"ConvertedNoteToIssueEvent"},{"name":"CrossReferencedEvent"},{"name":"DemilestonedEvent"},{"name":"DeployKey"},{"name":"DeployedEvent"},{"name":"Deployment"},{"name":"DeploymentEnvironmentChangedEvent"},{"name":"DeploymentStatus"},{"name":"ExternalIdentity"},{"name":"Gist"},{"name":"GistComment"},{"name":"HeadRefDeletedEvent"},{"name":"HeadRefForcePushedEvent"},{"name":"HeadRefRestoredEvent"},{"name":"Issue"},{"name":"IssueComment"},{"name":"Label"},{"name":"LabeledEvent"},{"name":"Language"},{"name":"License"},{"name":"LockedEvent"},{"name":"Mannequin"},{"name":"MarketplaceCategory"},{"name":"MarketplaceListing"},{"name":"MentionedEvent"},{"name":"MergedEvent"},{"name":"Milestone"},{"name":"MilestonedEvent"},{"name":"MovedColumnsInProjectEvent"},{"name":"Organization"},{"name":"OrganizationIdentityProvider"},{"name":"OrganizationInvitation"},{"name":"PinnedEvent"},{"name":"Project"},{"name":"ProjectCard"},{"name":"ProjectColumn"},{"name":"PublicKey"},{"name":"PullRequest"},{"name":"PullRequestCommit"},{"name":"PullRequestCommitCommentThread"},{"name":"PullRequestReview"},{"name":"PullRequestReviewComment"},{"name":"PullRequestReviewThread"},{"name":"PushAllowance"},{"name":"Reaction"},{"name":"ReadyForReviewEvent"},{"name":"Ref"},{"name":"ReferencedEvent"},{"name":"RegistryPackage"},{"name":"RegistryPackageDependency"},{"name":"RegistryPackageFile"},{"name":"RegistryPackageTag"},{"name":"RegistryPackageVersion"},{"name":"Release"},{"name":"ReleaseAsset"},{"name":"RemovedFromProjectEvent"},{"name":"RenamedTitleEvent"},{"name":"ReopenedEvent"},{"name":"Repository"},{"name":"RepositoryInvitation"},{"name":"RepositoryTopic"},{"name":"ReviewDismissalAllowance"},{"name":"ReviewDismissedEvent"},{"name":"ReviewRequest"},{"name":"ReviewRequestRemovedEvent"},{"name":"ReviewRequestedEvent"},{"name":"SavedReply"},{"name":"SecurityAdvisory"},{"name":"SponsorsListing"},{"name":"Sponsorship"},{"name":"Status"},{"name":"StatusContext"},{"name":"SubscribedEvent"},{"name":"Tag"},{"name":"Team"},{"name":"Topic"},{"name":"TransferredEvent"},{"name":"Tree"},{"name":"UnassignedEvent"},{"name":"UnlabeledEvent"},{"name":"UnlockedEvent"},{"name":"UnpinnedEvent"},{"name":"UnsubscribedEvent"},{"name":"User"},{"name":"UserBlockedEvent"},{"name":"UserContentEdit"},{"name":"UserStatus"}]},{"kind":"INTERFACE","name":"UniformResourceLocatable","possibleTypes":[{"name":"Bot"},{"name":"ClosedEvent"},{"name":"Commit"},{"name":"CrossReferencedEvent"},{"name":"Gist"},{"name":"Issue"},{"name":"Mannequin"},{"name":"MergedEvent"},{"name":"Milestone"},{"name":"Organization"},{"name":"PullRequest"},{"name":"PullRequestCommit"},{"name":"ReadyForReviewEvent"},{"name":"Release"},{"name":"Repository"},{"name":"RepositoryTopic"},{"name":"ReviewDismissedEvent"},{"name":"User"}]},{"kind":"INTERFACE","name":"Actor","possibleTypes":[{"name":"Bot"},{"name":"Mannequin"},{"name":"Organization"},{"name":"User"}]},{"kind":"INTERFACE","name":"RegistryPackageOwner","possibleTypes":[{"name":"Organization"},{"name":"Repository"},{"name":"User"}]},{"kind":"INTERFACE","name":"ProjectOwner","possibleTypes":[{"name":"Organization"},{"name":"Repository"},{"name":"User"}]},{"kind":"INTERFACE","name":"Closable","possibleTypes":[{"name":"Issue"},{"name":"Milestone"},{"name":"Project"},{"name":"PullRequest"}]},{"kind":"INTERFACE","name":"Updatable","possibleTypes":[{"name":"CommitComment"},{"name":"GistComment"},{"name":"Issue"},{"name":"IssueComment"},{"name":"Project"},{"name":"PullRequest"},{"name":"PullRequestReview"},{"name":"PullRequestReviewComment"}]},{"kind":"UNION","name":"ProjectCardItem","possibleTypes":[{"name":"Issue"},{"name":"PullRequest"}]},{"kind":"INTERFACE","name":"Assignable","possibleTypes":[{"name":"Issue"},{"name":"PullRequest"}]},{"kind":"INTERFACE","name":"Comment","possibleTypes":[{"name":"CommitComment"},{"name":"GistComment"},{"name":"Issue"},{"name":"IssueComment"},{"name":"PullRequest"},{"name":"PullRequestReview"},{"name":"PullRequestReviewComment"}]},{"kind":"INTERFACE","name":"UpdatableComment","possibleTypes":[{"name":"CommitComment"},{"name":"GistComment"},{"name":"Issue"},{"name":"IssueComment"},{"name":"PullRequest"},{"name":"PullRequestReview"},{"name":"PullRequestReviewComment"}]},{"kind":"INTERFACE","name":"Labelable","possibleTypes":[{"name":"Issue"},{"name":"PullRequest"}]},{"kind":"INTERFACE","name":"Lockable","possibleTypes":[{"name":"Issue"},{"name":"PullRequest"}]},{"kind":"INTERFACE","name":"RegistryPackageSearch","possibleTypes":[{"name":"Organization"},{"name":"User"}]},{"kind":"INTERFACE","name":"RepositoryOwner","possibleTypes":[{"name":"Organization"},{"name":"User"}]},{"kind":"INTERFACE","name":"MemberStatusable","possibleTypes":[{"name":"Organization"},{"name":"Team"}]},{"kind":"INTERFACE","name":"ProfileOwner","possibleTypes":[{"name":"Organization"},{"name":"User"}]},{"kind":"UNION","name":"PinnableItem","possibleTypes":[{"name":"Gist"},{"name":"Repository"}]},{"kind":"INTERFACE","name":"Starrable","possibleTypes":[{"name":"Gist"},{"name":"Repository"},{"name":"Topic"}]},{"kind":"INTERFACE","name":"RepositoryInfo","possibleTypes":[{"name":"Repository"}]},{"kind":"INTERFACE","name":"GitObject","possibleTypes":[{"name":"Blob"},{"name":"Commit"},{"name":"Tag"},{"name":"Tree"}]},{"kind":"INTERFACE","name":"RepositoryNode","possibleTypes":[{"name":"CommitComment"},{"name":"CommitCommentThread"},{"name":"Issue"},{"name":"IssueComment"},{"name":"PullRequest"},{"name":"PullRequestCommitCommentThread"},{"name":"PullRequestReview"},{"name":"PullRequestReviewComment"}]},{"kind":"INTERFACE","name":"Subscribable","possibleTypes":[{"name":"Commit"},{"name":"Issue"},{"name":"PullRequest"},{"name":"Repository"},{"name":"Team"}]},{"kind":"INTERFACE","name":"Deletable","possibleTypes":[{"name":"CommitComment"},{"name":"GistComment"},{"name":"IssueComment"},{"name":"PullRequestReview"},{"name":"PullRequestReviewComment"}]},{"kind":"INTERFACE","name":"Reactable","possibleTypes":[{"name":"CommitComment"},{"name":"Issue"},{"name":"IssueComment"},{"name":"PullRequest"},{"name":"PullRequestReview"},{"name":"PullRequestReviewComment"}]},{"kind":"INTERFACE","name":"GitSignature","possibleTypes":[{"name":"GpgSignature"},{"name":"SmimeSignature"},{"name":"UnknownSignature"}]},{"kind":"UNION","name":"RequestedReviewer","possibleTypes":[{"name":"User"},{"name":"Team"},{"name":"Mannequin"}]},{"kind":"UNION","name":"PullRequestTimelineItem","possibleTypes":[{"name":"Commit"},{"name":"CommitCommentThread"},{"name":"PullRequestReview"},{"name":"PullRequestReviewThread"},{"name":"PullRequestReviewComment"},{"name":"IssueComment"},{"name":"ClosedEvent"},{"name":"ReopenedEvent"},{"name":"SubscribedEvent"},{"name":"UnsubscribedEvent"},{"name":"MergedEvent"},{"name":"ReferencedEvent"},{"name":"CrossReferencedEvent"},{"name":"AssignedEvent"},{"name":"UnassignedEvent"},{"name":"LabeledEvent"},{"name":"UnlabeledEvent"},{"name":"MilestonedEvent"},{"name":"DemilestonedEvent"},{"name":"RenamedTitleEvent"},{"name":"LockedEvent"},{"name":"UnlockedEvent"},{"name":"DeployedEvent"},{"name":"DeploymentEnvironmentChangedEvent"},{"name":"HeadRefDeletedEvent"},{"name":"HeadRefRestoredEvent"},{"name":"HeadRefForcePushedEvent"},{"name":"BaseRefForcePushedEvent"},{"name":"ReviewRequestedEvent"},{"name":"ReviewRequestRemovedEvent"},{"name":"ReviewDismissedEvent"},{"name":"UserBlockedEvent"}]},{"kind":"UNION","name":"Closer","possibleTypes":[{"name":"Commit"},{"name":"PullRequest"}]},{"kind":"UNION","name":"ReferencedSubject","possibleTypes":[{"name":"Issue"},{"name":"PullRequest"}]},{"kind":"UNION","name":"Assignee","possibleTypes":[{"name":"Bot"},{"name":"Mannequin"},{"name":"Organization"},{"name":"User"}]},{"kind":"UNION","name":"MilestoneItem","possibleTypes":[{"name":"Issue"},{"name":"PullRequest"}]},{"kind":"UNION","name":"RenamedTitleSubject","possibleTypes":[{"name":"Issue"},{"name":"PullRequest"}]},{"kind":"UNION","name":"PullRequestTimelineItems","possibleTypes":[{"name":"PullRequestCommit"},{"name":"PullRequestCommitCommentThread"},{"name":"PullRequestReview"},{"name":"PullRequestReviewThread"},{"name":"PullRequestRevisionMarker"},{"name":"BaseRefChangedEvent"},{"name":"BaseRefForcePushedEvent"},{"name":"DeployedEvent"},{"name":"DeploymentEnvironmentChangedEvent"},{"name":"HeadRefDeletedEvent"},{"name":"HeadRefForcePushedEvent"},{"name":"HeadRefRestoredEvent"},{"name":"MergedEvent"},{"name":"ReviewDismissedEvent"},{"name":"ReviewRequestedEvent"},{"name":"ReviewRequestRemovedEvent"},{"name":"ReadyForReviewEvent"},{"name":"IssueComment"},{"name":"CrossReferencedEvent"},{"name":"AddedToProjectEvent"},{"name":"AssignedEvent"},{"name":"ClosedEvent"},{"name":"CommentDeletedEvent"},{"name":"ConvertedNoteToIssueEvent"},{"name":"DemilestonedEvent"},{"name":"LabeledEvent"},{"name":"LockedEvent"},{"name":"MentionedEvent"},{"name":"MilestonedEvent"},{"name":"MovedColumnsInProjectEvent"},{"name":"PinnedEvent"},{"name":"ReferencedEvent"},{"name":"RemovedFromProjectEvent"},{"name":"RenamedTitleEvent"},{"name":"ReopenedEvent"},{"name":"SubscribedEvent"},{"name":"TransferredEvent"},{"name":"UnassignedEvent"},{"name":"UnlabeledEvent"},{"name":"UnlockedEvent"},{"name":"UserBlockedEvent"},{"name":"UnpinnedEvent"},{"name":"UnsubscribedEvent"}]},{"kind":"UNION","name":"IssueOrPullRequest","possibleTypes":[{"name":"Issue"},{"name":"PullRequest"}]},{"kind":"UNION","name":"IssueTimelineItem","possibleTypes":[{"name":"Commit"},{"name":"IssueComment"},{"name":"CrossReferencedEvent"},{"name":"ClosedEvent"},{"name":"ReopenedEvent"},{"name":"SubscribedEvent"},{"name":"UnsubscribedEvent"},{"name":"ReferencedEvent"},{"name":"AssignedEvent"},{"name":"UnassignedEvent"},{"name":"LabeledEvent"},{"name":"UnlabeledEvent"},{"name":"UserBlockedEvent"},{"name":"MilestonedEvent"},{"name":"DemilestonedEvent"},{"name":"RenamedTitleEvent"},{"name":"LockedEvent"},{"name":"UnlockedEvent"},{"name":"TransferredEvent"}]},{"kind":"UNION","name":"IssueTimelineItems","possibleTypes":[{"name":"IssueComment"},{"name":"CrossReferencedEvent"},{"name":"AddedToProjectEvent"},{"name":"AssignedEvent"},{"name":"ClosedEvent"},{"name":"CommentDeletedEvent"},{"name":"ConvertedNoteToIssueEvent"},{"name":"DemilestonedEvent"},{"name":"LabeledEvent"},{"name":"LockedEvent"},{"name":"MentionedEvent"},{"name":"MilestonedEvent"},{"name":"MovedColumnsInProjectEvent"},{"name":"PinnedEvent"},{"name":"ReferencedEvent"},{"name":"RemovedFromProjectEvent"},{"name":"RenamedTitleEvent"},{"name":"ReopenedEvent"},{"name":"SubscribedEvent"},{"name":"TransferredEvent"},{"name":"UnassignedEvent"},{"name":"UnlabeledEvent"},{"name":"UnlockedEvent"},{"name":"UserBlockedEvent"},{"name":"UnpinnedEvent"},{"name":"UnsubscribedEvent"}]},{"kind":"UNION","name":"ReviewDismissalAllowanceActor","possibleTypes":[{"name":"User"},{"name":"Team"}]},{"kind":"UNION","name":"PushAllowanceActor","possibleTypes":[{"name":"User"},{"name":"Team"}]},{"kind":"UNION","name":"PermissionGranter","possibleTypes":[{"name":"Organization"},{"name":"Repository"},{"name":"Team"}]},{"kind":"INTERFACE","name":"Sponsorable","possibleTypes":[{"name":"User"}]},{"kind":"INTERFACE","name":"Contribution","possibleTypes":[{"name":"CreatedCommitContribution"},{"name":"CreatedIssueContribution"},{"name":"CreatedPullRequestContribution"},{"name":"CreatedPullRequestReviewContribution"},{"name":"CreatedRepositoryContribution"},{"name":"JoinedGitHubContribution"},{"name":"RestrictedContribution"}]},{"kind":"UNION","name":"CreatedRepositoryOrRestrictedContribution","possibleTypes":[{"name":"CreatedRepositoryContribution"},{"name":"RestrictedContribution"}]},{"kind":"UNION","name":"CreatedIssueOrRestrictedContribution","possibleTypes":[{"name":"CreatedIssueContribution"},{"name":"RestrictedContribution"}]},{"kind":"UNION","name":"CreatedPullRequestOrRestrictedContribution","possibleTypes":[{"name":"CreatedPullRequestContribution"},{"name":"RestrictedContribution"}]},{"kind":"UNION","name":"SearchResultItem","possibleTypes":[{"name":"Issue"},{"name":"PullRequest"},{"name":"Repository"},{"name":"User"},{"name":"Organization"},{"name":"MarketplaceListing"},{"name":"App"}]},{"kind":"UNION","name":"CollectionItemContent","possibleTypes":[{"name":"Repository"},{"name":"Organization"},{"name":"User"}]}]}}
@@ -0,0 +1,92 @@
1
+ import { gql } from 'graphql-tag';
2
+
3
+ export const repository = gql`
4
+ fragment RepositoryParts on Repository {
5
+ id
6
+ isFork
7
+ }
8
+ `;
9
+
10
+ export const blobWithText = gql`
11
+ fragment BlobWithTextParts on Blob {
12
+ id
13
+ text
14
+ is_binary: isBinary
15
+ }
16
+ `;
17
+
18
+ export const object = gql`
19
+ fragment ObjectParts on GitObject {
20
+ id
21
+ sha: oid
22
+ }
23
+ `;
24
+
25
+ export const branch = gql`
26
+ fragment BranchParts on Ref {
27
+ commit: target {
28
+ ...ObjectParts
29
+ }
30
+ id
31
+ name
32
+ prefix
33
+ repository {
34
+ ...RepositoryParts
35
+ }
36
+ }
37
+ ${object}
38
+ ${repository}
39
+ `;
40
+
41
+ export const pullRequest = gql`
42
+ fragment PullRequestParts on PullRequest {
43
+ id
44
+ baseRefName
45
+ baseRefOid
46
+ body
47
+ headRefName
48
+ headRefOid
49
+ number
50
+ state
51
+ title
52
+ merged_at: mergedAt
53
+ updated_at: updatedAt
54
+ user: author {
55
+ login
56
+ ... on User {
57
+ name
58
+ }
59
+ }
60
+ repository {
61
+ ...RepositoryParts
62
+ }
63
+ labels(last: 100) {
64
+ nodes {
65
+ name
66
+ }
67
+ }
68
+ }
69
+ ${repository}
70
+ `;
71
+
72
+ export const treeEntry = gql`
73
+ fragment TreeEntryParts on TreeEntry {
74
+ path: name
75
+ sha: oid
76
+ type
77
+ mode
78
+ }
79
+ `;
80
+
81
+ export const fileEntry = gql`
82
+ fragment FileEntryParts on TreeEntry {
83
+ name
84
+ sha: oid
85
+ type
86
+ blob: object {
87
+ ... on Blob {
88
+ size: byteSize
89
+ }
90
+ }
91
+ }
92
+ `;