Skip to content

Commit fb9c8c2

Browse files
committed
Adding current sha in the payload
1 parent b4effc7 commit fb9c8c2

3 files changed

Lines changed: 21 additions & 23 deletions

File tree

script/apiClient.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,20 @@ import API_CONFIG from './apiConfig.js';
33
import gitUtils from './gitUtils.js';
44

55
const { BASE_URL } = API_CONFIG;
6-
const { getGitUser, getRepoName } = gitUtils;
6+
const { getRepoInfo } = gitUtils;
77

88
/**
99
* Sends commit data to the backend.
1010
* @param {object} commitData The commit data to send.
1111
*/
1212
async function sendCommit(commitData) {
1313
try {
14-
const userId = getGitUser();
15-
const repoName = getRepoName();
14+
const { owner, name } = getRepoInfo();
1615

1716
const payload = {
1817
...commitData,
19-
user_id: userId,
20-
repo_name: repoName,
18+
user_id: owner, // Use repo owner as user_id for querying
19+
repo_name: name, // Use repo name
2120
};
2221

2322
console.log('Sending data to /commits endpoint...');
@@ -35,13 +34,12 @@ async function sendCommit(commitData) {
3534
*/
3635
async function sendTestRuns(batchData) {
3736
try {
38-
const userId = getGitUser();
39-
const repoName = getRepoName();
37+
const { owner, name } = getRepoInfo();
4038

4139
const payload = {
4240
...batchData,
43-
user_id: userId,
44-
repo_name: repoName,
41+
user_id: owner, // Use repo owner as user_id for querying
42+
repo_name: name, // Use repo name
4543
};
4644

4745
console.log('Sending test runs batch to /test-runs endpoint...');
@@ -59,3 +57,4 @@ const apiClient = {
5957

6058

6159
export default apiClient;
60+

script/commit-tracker.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ try {
9595
// 1. Send aggregated commit data to backend
9696
const commitPayload = {
9797
_id: currentSha,
98+
sha: currentSha,
9899
branch: branchName,
99100
author: currentCommitData.author,
100101
commit: currentCommitData.commit,

script/gitUtils.js

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,27 @@ function getGitUser() {
99
}
1010
}
1111

12-
function getRepoName() {
12+
function getRepoInfo() {
1313
try {
1414
const remoteUrl = execSync('git remote get-url origin').toString().trim();
15-
// Extracts 'repo-name' from URLs like:
16-
// https://github.com/user/repo-name.git
17-
// git@github.com:user/repo-name.git
18-
const repoNameMatch = remoteUrl.match(/[:/]([^/]+\/[^/]+)\.git$/);
19-
if (repoNameMatch && repoNameMatch[1]) {
20-
// We are interested in the repo name, not the user/repo
21-
const parts = repoNameMatch[1].split('/');
22-
return parts[1];
15+
// Extracts 'owner/repo-name' from URLs like:
16+
// https://github.com/owner/repo-name.git
17+
// git@github.com:owner/repo-name.git
18+
const repoInfoMatch = remoteUrl.match(/[:/]([^/]+\/[^/]+)\.git$/);
19+
if (repoInfoMatch && repoInfoMatch[1]) {
20+
const [owner, name] = repoInfoMatch[1].split('/');
21+
return { owner, name };
2322
}
24-
return 'unknown_repo';
23+
return { owner: 'unknown_owner', name: 'unknown_repo' };
2524
} catch (error) {
26-
console.error('Error getting Git repository name:', error.message);
27-
// This can happen if there is no remote named 'origin'
28-
return 'unknown_repo';
25+
console.error('Error getting Git repository info:', error.message);
26+
return { owner: 'unknown_owner', name: 'unknown_repo' };
2927
}
3028
}
3129

3230
const gitUtils = {
3331
getGitUser,
34-
getRepoName,
32+
getRepoInfo,
3533
};
3634

3735

0 commit comments

Comments
 (0)