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,34 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "API", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _API.default;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "AuthenticationPage", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _AuthenticationPage.default;
16
+ }
17
+ });
18
+ exports.DecapCmsBackendGithub = void 0;
19
+ Object.defineProperty(exports, "GitHubBackend", {
20
+ enumerable: true,
21
+ get: function () {
22
+ return _implementation.default;
23
+ }
24
+ });
25
+ var _implementation = _interopRequireDefault(require("./implementation"));
26
+ var _API = _interopRequireDefault(require("./API"));
27
+ var _AuthenticationPage = _interopRequireDefault(require("./AuthenticationPage"));
28
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
29
+ const DecapCmsBackendGithub = {
30
+ GitHubBackend: _implementation.default,
31
+ API: _API.default,
32
+ AuthenticationPage: _AuthenticationPage.default
33
+ };
34
+ exports.DecapCmsBackendGithub = DecapCmsBackendGithub;
@@ -0,0 +1,117 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.updateBranch = exports.reopenPullRequest = exports.deleteBranch = exports.createPullRequest = exports.createBranchAndPullRequest = exports.createBranch = exports.closePullRequestAndDeleteBranch = exports.closePullRequest = void 0;
7
+ var _graphqlTag = require("graphql-tag");
8
+ var fragments = _interopRequireWildcard(require("./fragments"));
9
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
10
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
11
+ // updateRef only works for branches at the moment
12
+ const updateBranch = (0, _graphqlTag.gql)`
13
+ mutation updateRef($input: UpdateRefInput!) {
14
+ updateRef(input: $input) {
15
+ branch: ref {
16
+ ...BranchParts
17
+ }
18
+ }
19
+ }
20
+ ${fragments.branch}
21
+ `;
22
+
23
+ // deleteRef only works for branches at the moment
24
+ exports.updateBranch = updateBranch;
25
+ const deleteRefMutationPart = `
26
+ deleteRef(input: $deleteRefInput) {
27
+ clientMutationId
28
+ }
29
+ `;
30
+ const deleteBranch = (0, _graphqlTag.gql)`
31
+ mutation deleteRef($deleteRefInput: DeleteRefInput!) {
32
+ ${deleteRefMutationPart}
33
+ }
34
+ `;
35
+ exports.deleteBranch = deleteBranch;
36
+ const closePullRequestMutationPart = `
37
+ closePullRequest(input: $closePullRequestInput) {
38
+ clientMutationId
39
+ pullRequest {
40
+ ...PullRequestParts
41
+ }
42
+ }
43
+ `;
44
+ const closePullRequest = (0, _graphqlTag.gql)`
45
+ mutation closePullRequestAndDeleteBranch($closePullRequestInput: ClosePullRequestInput!) {
46
+ ${closePullRequestMutationPart}
47
+ }
48
+ ${fragments.pullRequest}
49
+ `;
50
+ exports.closePullRequest = closePullRequest;
51
+ const closePullRequestAndDeleteBranch = (0, _graphqlTag.gql)`
52
+ mutation closePullRequestAndDeleteBranch(
53
+ $closePullRequestInput: ClosePullRequestInput!
54
+ $deleteRefInput: DeleteRefInput!
55
+ ) {
56
+ ${closePullRequestMutationPart}
57
+ ${deleteRefMutationPart}
58
+ }
59
+ ${fragments.pullRequest}
60
+ `;
61
+ exports.closePullRequestAndDeleteBranch = closePullRequestAndDeleteBranch;
62
+ const createPullRequestMutationPart = `
63
+ createPullRequest(input: $createPullRequestInput) {
64
+ clientMutationId
65
+ pullRequest {
66
+ ...PullRequestParts
67
+ }
68
+ }
69
+ `;
70
+ const createPullRequest = (0, _graphqlTag.gql)`
71
+ mutation createPullRequest($createPullRequestInput: CreatePullRequestInput!) {
72
+ ${createPullRequestMutationPart}
73
+ }
74
+ ${fragments.pullRequest}
75
+ `;
76
+ exports.createPullRequest = createPullRequest;
77
+ const createBranch = (0, _graphqlTag.gql)`
78
+ mutation createBranch($createRefInput: CreateRefInput!) {
79
+ createRef(input: $createRefInput) {
80
+ branch: ref {
81
+ ...BranchParts
82
+ }
83
+ }
84
+ }
85
+ ${fragments.branch}
86
+ `;
87
+
88
+ // createRef only works for branches at the moment
89
+ exports.createBranch = createBranch;
90
+ const createBranchAndPullRequest = (0, _graphqlTag.gql)`
91
+ mutation createBranchAndPullRequest(
92
+ $createRefInput: CreateRefInput!
93
+ $createPullRequestInput: CreatePullRequestInput!
94
+ ) {
95
+ createRef(input: $createRefInput) {
96
+ branch: ref {
97
+ ...BranchParts
98
+ }
99
+ }
100
+ ${createPullRequestMutationPart}
101
+ }
102
+ ${fragments.branch}
103
+ ${fragments.pullRequest}
104
+ `;
105
+ exports.createBranchAndPullRequest = createBranchAndPullRequest;
106
+ const reopenPullRequest = (0, _graphqlTag.gql)`
107
+ mutation reopenPullRequest($reopenPullRequestInput: ReopenPullRequestInput!) {
108
+ reopenPullRequest(input: $reopenPullRequestInput) {
109
+ clientMutationId
110
+ pullRequest {
111
+ ...PullRequestParts
112
+ }
113
+ }
114
+ }
115
+ ${fragments.pullRequest}
116
+ `;
117
+ exports.reopenPullRequest = reopenPullRequest;
@@ -0,0 +1,212 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.fileSha = exports.branch = exports.blob = void 0;
7
+ exports.files = files;
8
+ exports.user = exports.statues = exports.repository = exports.repoPermission = exports.pullRequests = exports.pullRequestAndBranch = exports.pullRequest = exports.openAuthoringBranches = void 0;
9
+ var _graphqlTag = require("graphql-tag");
10
+ var _commonTags = require("common-tags");
11
+ var fragments = _interopRequireWildcard(require("./fragments"));
12
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
13
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
14
+ const repoPermission = (0, _graphqlTag.gql)`
15
+ query repoPermission($owner: String!, $name: String!) {
16
+ repository(owner: $owner, name: $name) {
17
+ ...RepositoryParts
18
+ viewerPermission
19
+ }
20
+ }
21
+ ${fragments.repository}
22
+ `;
23
+ exports.repoPermission = repoPermission;
24
+ const user = (0, _graphqlTag.gql)`
25
+ query {
26
+ viewer {
27
+ id
28
+ avatar_url: avatarUrl
29
+ name
30
+ login
31
+ }
32
+ }
33
+ `;
34
+ exports.user = user;
35
+ const blob = (0, _graphqlTag.gql)`
36
+ query blob($owner: String!, $name: String!, $expression: String!) {
37
+ repository(owner: $owner, name: $name) {
38
+ ...RepositoryParts
39
+ object(expression: $expression) {
40
+ ... on Blob {
41
+ ...BlobWithTextParts
42
+ }
43
+ }
44
+ }
45
+ }
46
+ ${fragments.repository}
47
+ ${fragments.blobWithText}
48
+ `;
49
+ exports.blob = blob;
50
+ const statues = (0, _graphqlTag.gql)`
51
+ query statues($owner: String!, $name: String!, $sha: GitObjectID!) {
52
+ repository(owner: $owner, name: $name) {
53
+ ...RepositoryParts
54
+ object(oid: $sha) {
55
+ ...ObjectParts
56
+ ... on Commit {
57
+ status {
58
+ id
59
+ contexts {
60
+ id
61
+ context
62
+ state
63
+ target_url: targetUrl
64
+ }
65
+ }
66
+ }
67
+ }
68
+ }
69
+ }
70
+ ${fragments.repository}
71
+ ${fragments.object}
72
+ `;
73
+ exports.statues = statues;
74
+ function buildFilesQuery(depth = 1) {
75
+ const PLACE_HOLDER = 'PLACE_HOLDER';
76
+ let query = (0, _commonTags.oneLine)`
77
+ ...ObjectParts
78
+ ... on Tree {
79
+ entries {
80
+ ...FileEntryParts
81
+ ${PLACE_HOLDER}
82
+ }
83
+ }
84
+ `;
85
+ for (let i = 0; i < depth - 1; i++) {
86
+ query = query.replace(PLACE_HOLDER, (0, _commonTags.oneLine)`
87
+ object {
88
+ ... on Tree {
89
+ entries {
90
+ ...FileEntryParts
91
+ ${PLACE_HOLDER}
92
+ }
93
+ }
94
+ }
95
+ `);
96
+ }
97
+ query = query.replace(PLACE_HOLDER, '');
98
+ return query;
99
+ }
100
+ function files(depth) {
101
+ return (0, _graphqlTag.gql)`
102
+ query files($owner: String!, $name: String!, $expression: String!) {
103
+ repository(owner: $owner, name: $name) {
104
+ ...RepositoryParts
105
+ object(expression: $expression) {
106
+ ${buildFilesQuery(depth)}
107
+ }
108
+ }
109
+ }
110
+ ${fragments.repository}
111
+ ${fragments.object}
112
+ ${fragments.fileEntry}
113
+ `;
114
+ }
115
+ const branchQueryPart = `
116
+ branch: ref(qualifiedName: $qualifiedName) {
117
+ ...BranchParts
118
+ }
119
+ `;
120
+ const branch = (0, _graphqlTag.gql)`
121
+ query branch($owner: String!, $name: String!, $qualifiedName: String!) {
122
+ repository(owner: $owner, name: $name) {
123
+ ...RepositoryParts
124
+ ${branchQueryPart}
125
+ }
126
+ }
127
+ ${fragments.repository}
128
+ ${fragments.branch}
129
+ `;
130
+ exports.branch = branch;
131
+ const openAuthoringBranches = (0, _graphqlTag.gql)`
132
+ query openAuthoringBranches($owner: String!, $name: String!, $refPrefix: String!) {
133
+ repository(owner: $owner, name: $name) {
134
+ ...RepositoryParts
135
+ refs(refPrefix: $refPrefix, last: 100) {
136
+ nodes {
137
+ ...BranchParts
138
+ }
139
+ }
140
+ }
141
+ }
142
+ ${fragments.repository}
143
+ ${fragments.branch}
144
+ `;
145
+ exports.openAuthoringBranches = openAuthoringBranches;
146
+ const repository = (0, _graphqlTag.gql)`
147
+ query repository($owner: String!, $name: String!) {
148
+ repository(owner: $owner, name: $name) {
149
+ ...RepositoryParts
150
+ }
151
+ }
152
+ ${fragments.repository}
153
+ `;
154
+ exports.repository = repository;
155
+ const pullRequestQueryPart = `
156
+ pullRequest(number: $number) {
157
+ ...PullRequestParts
158
+ }
159
+ `;
160
+ const pullRequest = (0, _graphqlTag.gql)`
161
+ query pullRequest($owner: String!, $name: String!, $number: Int!) {
162
+ repository(owner: $owner, name: $name) {
163
+ id
164
+ ${pullRequestQueryPart}
165
+ }
166
+ }
167
+ ${fragments.pullRequest}
168
+ `;
169
+ exports.pullRequest = pullRequest;
170
+ const pullRequests = (0, _graphqlTag.gql)`
171
+ query pullRequests($owner: String!, $name: String!, $head: String, $states: [PullRequestState!]) {
172
+ repository(owner: $owner, name: $name) {
173
+ id
174
+ pullRequests(last: 100, headRefName: $head, states: $states) {
175
+ nodes {
176
+ ...PullRequestParts
177
+ }
178
+ }
179
+ }
180
+ }
181
+ ${fragments.pullRequest}
182
+ `;
183
+ exports.pullRequests = pullRequests;
184
+ const pullRequestAndBranch = (0, _graphqlTag.gql)`
185
+ query pullRequestAndBranch($owner: String!, $name: String!, $originRepoOwner: String!, $originRepoName: String!, $qualifiedName: String!, $number: Int!) {
186
+ repository(owner: $owner, name: $name) {
187
+ ...RepositoryParts
188
+ ${branchQueryPart}
189
+ }
190
+ origin: repository(owner: $originRepoOwner, name: $originRepoName) {
191
+ ...RepositoryParts
192
+ ${pullRequestQueryPart}
193
+ }
194
+ }
195
+ ${fragments.repository}
196
+ ${fragments.branch}
197
+ ${fragments.pullRequest}
198
+ `;
199
+ exports.pullRequestAndBranch = pullRequestAndBranch;
200
+ const fileSha = (0, _graphqlTag.gql)`
201
+ query fileSha($owner: String!, $name: String!, $expression: String!) {
202
+ repository(owner: $owner, name: $name) {
203
+ ...RepositoryParts
204
+ file: object(expression: $expression) {
205
+ ...ObjectParts
206
+ }
207
+ }
208
+ }
209
+ ${fragments.repository}
210
+ ${fragments.object}
211
+ `;
212
+ exports.fileSha = fileSha;
@@ -0,0 +1 @@
1
+ "use strict";
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "decap-cms-backend-github",
3
+ "description": "GitHub backend for Decap CMS",
4
+ "version": "2.15.0-beta.0",
5
+ "license": "MIT",
6
+ "repository": "https://github.com/decaporg/decap-cms/tree/master/packages/decap-cms-backend-github",
7
+ "bugs": "https://github.com/decaporg/decap-cms/issues",
8
+ "module": "dist/esm/index.js",
9
+ "main": "dist/decap-cms-backend-github.js",
10
+ "keywords": [
11
+ "decap-cms",
12
+ "backend",
13
+ "github"
14
+ ],
15
+ "sideEffects": false,
16
+ "scripts": {
17
+ "develop": "yarn build:esm --watch",
18
+ "build": "cross-env NODE_ENV=production webpack",
19
+ "build:esm": "cross-env NODE_ENV=esm babel src --out-dir dist/esm --ignore \"**/__tests__\" --root-mode upward --extensions \".js,.jsx,.ts,.tsx\"",
20
+ "createFragmentTypes": "node scripts/createFragmentTypes.js"
21
+ },
22
+ "dependencies": {
23
+ "apollo-cache-inmemory": "^1.6.2",
24
+ "apollo-client": "^2.6.3",
25
+ "apollo-link-context": "^1.0.18",
26
+ "apollo-link-http": "^1.5.15",
27
+ "common-tags": "^1.8.0",
28
+ "graphql": "^15.0.0",
29
+ "graphql-tag": "^2.10.1",
30
+ "js-base64": "^3.0.0",
31
+ "semaphore": "^1.1.0"
32
+ },
33
+ "peerDependencies": {
34
+ "@emotion/core": "^10.0.35",
35
+ "@emotion/styled": "^10.0.27",
36
+ "decap-cms-lib-auth": "^2.3.0",
37
+ "decap-cms-lib-util": "^2.12.3",
38
+ "decap-cms-ui-default": "^2.12.1",
39
+ "lodash": "^4.17.11",
40
+ "prop-types": "^15.7.2",
41
+ "react": "^16.8.4 || ^17.0.0"
42
+ },
43
+ "gitHead": "1bdf716e5655bf088a343cd90210a2d361a9db52"
44
+ }
@@ -0,0 +1,48 @@
1
+ const fetch = require('node-fetch');
2
+ const fs = require('fs');
3
+ const path = require('path');
4
+
5
+ const API_HOST = process.env.GITHUB_HOST || 'https://api.github.com';
6
+ const API_TOKEN = process.env.GITHUB_API_TOKEN;
7
+
8
+ if (!API_TOKEN) {
9
+ throw new Error('Missing environment variable GITHUB_API_TOKEN');
10
+ }
11
+
12
+ fetch(`${API_HOST}/graphql`, {
13
+ method: 'POST',
14
+ headers: { 'Content-Type': 'application/json', Authorization: `bearer ${API_TOKEN}` },
15
+ body: JSON.stringify({
16
+ variables: {},
17
+ query: `
18
+ {
19
+ __schema {
20
+ types {
21
+ kind
22
+ name
23
+ possibleTypes {
24
+ name
25
+ }
26
+ }
27
+ }
28
+ }
29
+ `,
30
+ }),
31
+ })
32
+ .then(result => result.json())
33
+ .then(result => {
34
+ // here we're filtering out any type information unrelated to unions or interfaces
35
+ const filteredData = result.data.__schema.types.filter(type => type.possibleTypes !== null);
36
+ result.data.__schema.types = filteredData;
37
+ fs.writeFile(
38
+ path.join(__dirname, '..', 'src', 'fragmentTypes.js'),
39
+ `module.exports = ${JSON.stringify(result.data)}`,
40
+ err => {
41
+ if (err) {
42
+ console.error('Error writing fragmentTypes file', err);
43
+ } else {
44
+ console.log('Fragment types successfully extracted!');
45
+ }
46
+ },
47
+ );
48
+ });