gent-cli 1.8.0 → 1.9.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.
- package/package.json +1 -1
- package/src/commands/push.js +3 -2
- package/src/services/repo-service.js +36 -36
- package/src/utils/cloud-sync.js +5 -4
- package/src/utils/constants.js +12 -12
package/package.json
CHANGED
package/src/commands/push.js
CHANGED
|
@@ -73,11 +73,12 @@ async function push(remoteName, branchName, options) {
|
|
|
73
73
|
let currentSha = branchCommitSha;
|
|
74
74
|
|
|
75
75
|
while (currentSha) {
|
|
76
|
-
const commit = commits.find(c => c.sha === currentSha);
|
|
76
|
+
const commit = commits.find(c => (c.sha || c.hash) === currentSha);
|
|
77
77
|
if (!commit) break;
|
|
78
78
|
|
|
79
79
|
commitsToPush.unshift(commit); // Add to beginning to maintain order
|
|
80
|
-
|
|
80
|
+
const parents = Array.isArray(commit.parent) ? commit.parent : (commit.parent ? [commit.parent] : []);
|
|
81
|
+
currentSha = parents.length > 0 ? parents[0] : null;
|
|
81
82
|
}
|
|
82
83
|
|
|
83
84
|
if (commitsToPush.length === 0) {
|
|
@@ -58,12 +58,12 @@ async function listRepositories() {
|
|
|
58
58
|
/**
|
|
59
59
|
* Get repository details
|
|
60
60
|
* @param {number} ownerId - Owner user ID
|
|
61
|
-
* @param {string}
|
|
61
|
+
* @param {string} projectName - Project name
|
|
62
62
|
* @returns {Promise<Object>} Repository data
|
|
63
63
|
*/
|
|
64
|
-
async function getRepository(ownerId,
|
|
64
|
+
async function getRepository(ownerId, projectName) {
|
|
65
65
|
try {
|
|
66
|
-
const url = buildUrl(API_ENDPOINTS.REPOS_GET, { owner_id: ownerId,
|
|
66
|
+
const url = buildUrl(API_ENDPOINTS.REPOS_GET, { owner_id: ownerId, project_name: projectName });
|
|
67
67
|
const response = await apiClient.get(url);
|
|
68
68
|
return response;
|
|
69
69
|
} catch (error) {
|
|
@@ -74,12 +74,12 @@ async function getRepository(ownerId, repoName) {
|
|
|
74
74
|
/**
|
|
75
75
|
* Delete a repository
|
|
76
76
|
* @param {number} ownerId - Owner user ID
|
|
77
|
-
* @param {string}
|
|
77
|
+
* @param {string} projectName - Project name
|
|
78
78
|
* @returns {Promise<Object>} Delete response
|
|
79
79
|
*/
|
|
80
|
-
async function deleteRepository(ownerId,
|
|
80
|
+
async function deleteRepository(ownerId, projectName) {
|
|
81
81
|
try {
|
|
82
|
-
const url = buildUrl(API_ENDPOINTS.REPOS_DELETE, { owner_id: ownerId,
|
|
82
|
+
const url = buildUrl(API_ENDPOINTS.REPOS_DELETE, { owner_id: ownerId, project_name: projectName });
|
|
83
83
|
const response = await apiClient.delete(url);
|
|
84
84
|
return response;
|
|
85
85
|
} catch (error) {
|
|
@@ -90,14 +90,14 @@ async function deleteRepository(ownerId, repoName) {
|
|
|
90
90
|
/**
|
|
91
91
|
* Create a blob (file content) in the repository
|
|
92
92
|
* @param {number} ownerId - Owner user ID
|
|
93
|
-
* @param {string}
|
|
93
|
+
* @param {string} projectName - Project name
|
|
94
94
|
* @param {string} content - File content
|
|
95
95
|
* @param {string} encoding - Encoding type (utf-8 or base64)
|
|
96
96
|
* @returns {Promise<Object>} Created blob data
|
|
97
97
|
*/
|
|
98
|
-
async function createBlob(ownerId,
|
|
98
|
+
async function createBlob(ownerId, projectName, content, encoding = 'utf-8') {
|
|
99
99
|
try {
|
|
100
|
-
const url = buildUrl(API_ENDPOINTS.BLOB_CREATE, { owner_id: ownerId,
|
|
100
|
+
const url = buildUrl(API_ENDPOINTS.BLOB_CREATE, { owner_id: ownerId, project_name: projectName });
|
|
101
101
|
const response = await apiClient.post(url, {
|
|
102
102
|
content,
|
|
103
103
|
encoding
|
|
@@ -111,13 +111,13 @@ async function createBlob(ownerId, repoName, content, encoding = 'utf-8') {
|
|
|
111
111
|
/**
|
|
112
112
|
* Get a blob by SHA
|
|
113
113
|
* @param {number} ownerId - Owner user ID
|
|
114
|
-
* @param {string}
|
|
114
|
+
* @param {string} projectName - Project name
|
|
115
115
|
* @param {string} sha - Blob SHA
|
|
116
116
|
* @returns {Promise<Object>} Blob data
|
|
117
117
|
*/
|
|
118
|
-
async function getBlob(ownerId,
|
|
118
|
+
async function getBlob(ownerId, projectName, sha) {
|
|
119
119
|
try {
|
|
120
|
-
const url = buildUrl(API_ENDPOINTS.BLOB_GET, { owner_id: ownerId,
|
|
120
|
+
const url = buildUrl(API_ENDPOINTS.BLOB_GET, { owner_id: ownerId, project_name: projectName, sha });
|
|
121
121
|
const response = await apiClient.get(url);
|
|
122
122
|
return response;
|
|
123
123
|
} catch (error) {
|
|
@@ -128,13 +128,13 @@ async function getBlob(ownerId, repoName, sha) {
|
|
|
128
128
|
/**
|
|
129
129
|
* Create a tree (directory structure) in the repository
|
|
130
130
|
* @param {number} ownerId - Owner user ID
|
|
131
|
-
* @param {string}
|
|
131
|
+
* @param {string} projectName - Project name
|
|
132
132
|
* @param {Array} entries - Tree entries
|
|
133
133
|
* @returns {Promise<Object>} Created tree data
|
|
134
134
|
*/
|
|
135
|
-
async function createTree(ownerId,
|
|
135
|
+
async function createTree(ownerId, projectName, entries) {
|
|
136
136
|
try {
|
|
137
|
-
const url = buildUrl(API_ENDPOINTS.TREE_CREATE, { owner_id: ownerId,
|
|
137
|
+
const url = buildUrl(API_ENDPOINTS.TREE_CREATE, { owner_id: ownerId, project_name: projectName });
|
|
138
138
|
const response = await apiClient.post(url, {
|
|
139
139
|
entries
|
|
140
140
|
});
|
|
@@ -147,13 +147,13 @@ async function createTree(ownerId, repoName, entries) {
|
|
|
147
147
|
/**
|
|
148
148
|
* Get a tree by SHA
|
|
149
149
|
* @param {number} ownerId - Owner user ID
|
|
150
|
-
* @param {string}
|
|
150
|
+
* @param {string} projectName - Project name
|
|
151
151
|
* @param {string} sha - Tree SHA
|
|
152
152
|
* @returns {Promise<Object>} Tree data
|
|
153
153
|
*/
|
|
154
|
-
async function getTree(ownerId,
|
|
154
|
+
async function getTree(ownerId, projectName, sha) {
|
|
155
155
|
try {
|
|
156
|
-
const url = buildUrl(API_ENDPOINTS.TREE_GET, { owner_id: ownerId,
|
|
156
|
+
const url = buildUrl(API_ENDPOINTS.TREE_GET, { owner_id: ownerId, project_name: projectName, sha });
|
|
157
157
|
const response = await apiClient.get(url);
|
|
158
158
|
return response;
|
|
159
159
|
} catch (error) {
|
|
@@ -164,13 +164,13 @@ async function getTree(ownerId, repoName, sha) {
|
|
|
164
164
|
/**
|
|
165
165
|
* Create a commit in the repository
|
|
166
166
|
* @param {number} ownerId - Owner user ID
|
|
167
|
-
* @param {string}
|
|
167
|
+
* @param {string} projectName - Project name
|
|
168
168
|
* @param {Object} commitData - Commit data (message, tree_sha, parent_shas, author_name, author_email, branch)
|
|
169
169
|
* @returns {Promise<Object>} Created commit data
|
|
170
170
|
*/
|
|
171
|
-
async function createCommit(ownerId,
|
|
171
|
+
async function createCommit(ownerId, projectName, commitData) {
|
|
172
172
|
try {
|
|
173
|
-
const url = buildUrl(API_ENDPOINTS.COMMITS_CREATE, { owner_id: ownerId,
|
|
173
|
+
const url = buildUrl(API_ENDPOINTS.COMMITS_CREATE, { owner_id: ownerId, project_name: projectName });
|
|
174
174
|
const response = await apiClient.post(url, commitData);
|
|
175
175
|
return response;
|
|
176
176
|
} catch (error) {
|
|
@@ -181,12 +181,12 @@ async function createCommit(ownerId, repoName, commitData) {
|
|
|
181
181
|
/**
|
|
182
182
|
* List all commits in a repository
|
|
183
183
|
* @param {number} ownerId - Owner user ID
|
|
184
|
-
* @param {string}
|
|
184
|
+
* @param {string} projectName - Project name
|
|
185
185
|
* @returns {Promise<Array>} List of commits
|
|
186
186
|
*/
|
|
187
|
-
async function listCommits(ownerId,
|
|
187
|
+
async function listCommits(ownerId, projectName) {
|
|
188
188
|
try {
|
|
189
|
-
const url = buildUrl(API_ENDPOINTS.COMMITS_LIST, { owner_id: ownerId,
|
|
189
|
+
const url = buildUrl(API_ENDPOINTS.COMMITS_LIST, { owner_id: ownerId, project_name: projectName });
|
|
190
190
|
const response = await apiClient.get(url);
|
|
191
191
|
return response;
|
|
192
192
|
} catch (error) {
|
|
@@ -197,13 +197,13 @@ async function listCommits(ownerId, repoName) {
|
|
|
197
197
|
/**
|
|
198
198
|
* Get a commit by SHA
|
|
199
199
|
* @param {number} ownerId - Owner user ID
|
|
200
|
-
* @param {string}
|
|
200
|
+
* @param {string} projectName - Project name
|
|
201
201
|
* @param {string} sha - Commit SHA
|
|
202
202
|
* @returns {Promise<Object>} Commit data
|
|
203
203
|
*/
|
|
204
|
-
async function getCommit(ownerId,
|
|
204
|
+
async function getCommit(ownerId, projectName, sha) {
|
|
205
205
|
try {
|
|
206
|
-
const url = buildUrl(API_ENDPOINTS.COMMITS_GET, { owner_id: ownerId,
|
|
206
|
+
const url = buildUrl(API_ENDPOINTS.COMMITS_GET, { owner_id: ownerId, project_name: projectName, sha });
|
|
207
207
|
const response = await apiClient.get(url);
|
|
208
208
|
return response;
|
|
209
209
|
} catch (error) {
|
|
@@ -214,14 +214,14 @@ async function getCommit(ownerId, repoName, sha) {
|
|
|
214
214
|
/**
|
|
215
215
|
* Create a branch in the repository
|
|
216
216
|
* @param {number} ownerId - Owner user ID
|
|
217
|
-
* @param {string}
|
|
217
|
+
* @param {string} projectName - Project name
|
|
218
218
|
* @param {string} branchName - Branch name
|
|
219
219
|
* @param {string} commitSha - Commit SHA to point the branch to
|
|
220
220
|
* @returns {Promise<Object>} Created branch data
|
|
221
221
|
*/
|
|
222
|
-
async function createBranch(ownerId,
|
|
222
|
+
async function createBranch(ownerId, projectName, branchName, commitSha) {
|
|
223
223
|
try {
|
|
224
|
-
const url = buildUrl(API_ENDPOINTS.BRANCHES_CREATE, { owner_id: ownerId,
|
|
224
|
+
const url = buildUrl(API_ENDPOINTS.BRANCHES_CREATE, { owner_id: ownerId, project_name: projectName });
|
|
225
225
|
const response = await apiClient.post(url, {
|
|
226
226
|
name: branchName,
|
|
227
227
|
commit_sha: commitSha
|
|
@@ -235,12 +235,12 @@ async function createBranch(ownerId, repoName, branchName, commitSha) {
|
|
|
235
235
|
/**
|
|
236
236
|
* List all branches in a repository
|
|
237
237
|
* @param {number} ownerId - Owner user ID
|
|
238
|
-
* @param {string}
|
|
238
|
+
* @param {string} projectName - Project name
|
|
239
239
|
* @returns {Promise<Array>} List of branches
|
|
240
240
|
*/
|
|
241
|
-
async function listBranches(ownerId,
|
|
241
|
+
async function listBranches(ownerId, projectName) {
|
|
242
242
|
try {
|
|
243
|
-
const url = buildUrl(API_ENDPOINTS.BRANCHES_LIST, { owner_id: ownerId,
|
|
243
|
+
const url = buildUrl(API_ENDPOINTS.BRANCHES_LIST, { owner_id: ownerId, project_name: projectName });
|
|
244
244
|
const response = await apiClient.get(url);
|
|
245
245
|
return response;
|
|
246
246
|
} catch (error) {
|
|
@@ -251,13 +251,13 @@ async function listBranches(ownerId, repoName) {
|
|
|
251
251
|
/**
|
|
252
252
|
* Get a branch by name
|
|
253
253
|
* @param {number} ownerId - Owner user ID
|
|
254
|
-
* @param {string}
|
|
254
|
+
* @param {string} projectName - Project name
|
|
255
255
|
* @param {string} branchName - Branch name
|
|
256
256
|
* @returns {Promise<Object>} Branch data
|
|
257
257
|
*/
|
|
258
|
-
async function getBranch(ownerId,
|
|
258
|
+
async function getBranch(ownerId, projectName, branchName) {
|
|
259
259
|
try {
|
|
260
|
-
const url = buildUrl(API_ENDPOINTS.BRANCHES_GET, { owner_id: ownerId,
|
|
260
|
+
const url = buildUrl(API_ENDPOINTS.BRANCHES_GET, { owner_id: ownerId, project_name: projectName, branch_name: branchName });
|
|
261
261
|
const response = await apiClient.get(url);
|
|
262
262
|
return response;
|
|
263
263
|
} catch (error) {
|
package/src/utils/cloud-sync.js
CHANGED
|
@@ -125,7 +125,7 @@ async function uploadCommit(commit, treeSha, ownerId, repoName, branchName) {
|
|
|
125
125
|
const commitData = {
|
|
126
126
|
message: commit.message,
|
|
127
127
|
tree_sha: treeSha,
|
|
128
|
-
parent_shas: commit.parent
|
|
128
|
+
parent_shas: Array.isArray(commit.parent) ? commit.parent : (commit.parent ? [commit.parent] : []),
|
|
129
129
|
author_name: commit.author.name,
|
|
130
130
|
author_email: commit.author.email,
|
|
131
131
|
branch: branchName
|
|
@@ -161,11 +161,12 @@ async function syncCommitsToCloud(commits, ownerId, repoName, branchName, cwd) {
|
|
|
161
161
|
|
|
162
162
|
// Read files from commit
|
|
163
163
|
const files = [];
|
|
164
|
-
|
|
165
|
-
|
|
164
|
+
const commitFiles = Array.isArray(commit.files) ? commit.files : [];
|
|
165
|
+
for (const file of commitFiles) {
|
|
166
|
+
const objectPath = path.join(cwd, GENT_DIR, OBJECTS_DIR, file.hash);
|
|
166
167
|
if (await pathExists(objectPath)) {
|
|
167
168
|
const content = await fs.readFile(objectPath, 'utf-8');
|
|
168
|
-
files.push({ path:
|
|
169
|
+
files.push({ path: file.path, content });
|
|
169
170
|
}
|
|
170
171
|
}
|
|
171
172
|
|
package/src/utils/constants.js
CHANGED
|
@@ -27,26 +27,26 @@ module.exports = {
|
|
|
27
27
|
// Repository endpoints
|
|
28
28
|
REPOS_LIST: '/api/repos/',
|
|
29
29
|
REPOS_CREATE: '/api/repos/create/',
|
|
30
|
-
REPOS_GET: '/api/repos/{owner_id}/{
|
|
31
|
-
REPOS_DELETE: '/api/repos/{owner_id}/{
|
|
30
|
+
REPOS_GET: '/api/repos/{owner_id}/{project_name}/',
|
|
31
|
+
REPOS_DELETE: '/api/repos/{owner_id}/{project_name}/delete/',
|
|
32
32
|
|
|
33
33
|
// Blob endpoints
|
|
34
|
-
BLOB_GET: '/api/repos/{owner_id}/{
|
|
35
|
-
BLOB_CREATE: '/api/repos/{owner_id}/{
|
|
34
|
+
BLOB_GET: '/api/repos/{owner_id}/{project_name}/blob/{sha}/',
|
|
35
|
+
BLOB_CREATE: '/api/repos/{owner_id}/{project_name}/blob/create/',
|
|
36
36
|
|
|
37
37
|
// Tree endpoints
|
|
38
|
-
TREE_GET: '/api/repos/{owner_id}/{
|
|
39
|
-
TREE_CREATE: '/api/repos/{owner_id}/{
|
|
38
|
+
TREE_GET: '/api/repos/{owner_id}/{project_name}/tree/{sha}/',
|
|
39
|
+
TREE_CREATE: '/api/repos/{owner_id}/{project_name}/tree/create/',
|
|
40
40
|
|
|
41
41
|
// Commit endpoints
|
|
42
|
-
COMMITS_LIST: '/api/repos/{owner_id}/{
|
|
43
|
-
COMMITS_GET: '/api/repos/{owner_id}/{
|
|
44
|
-
COMMITS_CREATE: '/api/repos/{owner_id}/{
|
|
42
|
+
COMMITS_LIST: '/api/repos/{owner_id}/{project_name}/commits/',
|
|
43
|
+
COMMITS_GET: '/api/repos/{owner_id}/{project_name}/commits/{sha}/',
|
|
44
|
+
COMMITS_CREATE: '/api/repos/{owner_id}/{project_name}/commits/create/',
|
|
45
45
|
|
|
46
46
|
// Branch endpoints
|
|
47
|
-
BRANCHES_LIST: '/api/repos/{owner_id}/{
|
|
48
|
-
BRANCHES_GET: '/api/repos/{owner_id}/{
|
|
49
|
-
BRANCHES_CREATE: '/api/repos/{owner_id}/{
|
|
47
|
+
BRANCHES_LIST: '/api/repos/{owner_id}/{project_name}/branches/',
|
|
48
|
+
BRANCHES_GET: '/api/repos/{owner_id}/{project_name}/branches/{branch_name}/',
|
|
49
|
+
BRANCHES_CREATE: '/api/repos/{owner_id}/{project_name}/branches/create/'
|
|
50
50
|
},
|
|
51
51
|
|
|
52
52
|
// Default ignore patterns
|