Skip to content

Commit 6082a6e

Browse files
committed
fetches all gitlab activites
1 parent 2de9e58 commit 6082a6e

File tree

1 file changed

+48
-78
lines changed

1 file changed

+48
-78
lines changed

src/scripts/scrumHelper.js

Lines changed: 48 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -559,94 +559,50 @@ ${userReason}`;
559559
}
560560

561561
function fetchGitlabData() {
562-
// First get user's projects
563-
var projectsUrl = `https://gitlab.com/api/v4/users/${gitlabUsername}/projects?per_page=100`;
564-
console.log('[GitLab] Fetching projects for user:', gitlabUsername, 'URL:', projectsUrl);
562+
// First get user's activities directly
563+
var issuesUrl = `https://gitlab.com/api/v4/issues?author_username=${gitlabUsername}&created_after=${getStartOfDayISO(startingDate)}&created_before=${getEndOfDayISO(endingDate)}&per_page=100&scope=all`;
564+
console.log('[GitLab] Fetching all issues:', issuesUrl);
565565

566+
// Fetch all issues created by the user
566567
$.ajax({
567568
dataType: 'json',
568569
type: 'GET',
569-
url: projectsUrl,
570+
url: issuesUrl,
570571
error: (xhr, textStatus, errorThrown) => {
571-
console.error('Error fetching GitLab projects:', {
572+
console.error('Error fetching GitLab issues:', {
572573
status: xhr.status,
573574
textStatus: textStatus,
574575
error: errorThrown
575576
});
576-
Materialize.toast('Error fetching GitLab projects. Please check your username.', 3000);
577+
Materialize.toast('Error fetching GitLab issues. Please check your username.', 3000);
577578
},
578-
success: (projects) => {
579-
console.log('[GitLab] Projects fetched:', projects.map(p => ({ id: p.id, name: p.name, path_with_namespace: p.path_with_namespace })));
580-
if (!projects || projects.length === 0) {
581-
Materialize.toast('No GitLab projects found for this user', 3000);
582-
return;
583-
}
579+
success: (issues) => {
580+
console.log('[GitLab] Issues fetched:', issues);
581+
gitlabIssuesData = issues;
582+
writeGitlabIssuesPrs();
583+
}
584+
});
584585

585-
// After fetching projects:
586-
projects.forEach(p => {
587-
gitlabProjectIdToName[p.id] = p.name;
588-
});
586+
// Fetch all merge requests created by the user
587+
var mrsUrl = `https://gitlab.com/api/v4/merge_requests?author_username=${gitlabUsername}&created_after=${getStartOfDayISO(startingDate)}&created_before=${getEndOfDayISO(endingDate)}&per_page=100&scope=all`;
588+
console.log('[GitLab] Fetching all MRs:', mrsUrl);
589589

590-
// Fetch issues and MRs for each project
591-
var projectIds = projects.map(p => p.id);
592-
var issuesPromises = [];
593-
var mrsPromises = [];
594-
595-
projectIds.forEach(projectId => {
596-
// Fetch issues
597-
var issuesUrl = `https://gitlab.com/api/v4/projects/${projectId}/issues?author_username=${gitlabUsername}&created_after=${getStartOfDayISO(startingDate)}&created_before=${getEndOfDayISO(endingDate)}&per_page=100`;
598-
console.log(`[GitLab] Fetching issues for project ${projectId}:`, issuesUrl);
599-
issuesPromises.push(
600-
$.ajax({
601-
dataType: 'json',
602-
type: 'GET',
603-
url: issuesUrl,
604-
success: function (data) {
605-
console.log(`[GitLab][DEBUG] Raw issues response for project ${projectId}:`, data);
606-
return data;
607-
},
608-
error: function (xhr, textStatus, errorThrown) {
609-
console.error(`[GitLab][ERROR] Issues API error for project ${projectId}:`, xhr.status, textStatus, errorThrown, xhr.responseText);
610-
return [];
611-
}
612-
})
613-
);
614-
615-
// Fetch merge requests
616-
var mrsUrl = `https://gitlab.com/api/v4/projects/${projectId}/merge_requests?author_username=${gitlabUsername}&created_after=${getStartOfDayISO(startingDate)}&created_before=${getEndOfDayISO(endingDate)}&per_page=100`;
617-
console.log(`[GitLab] Fetching MRs for project ${projectId}:`, mrsUrl);
618-
mrsPromises.push(
619-
$.ajax({
620-
dataType: 'json',
621-
type: 'GET',
622-
url: mrsUrl
623-
})
624-
);
590+
$.ajax({
591+
dataType: 'json',
592+
type: 'GET',
593+
url: mrsUrl,
594+
error: (xhr, textStatus, errorThrown) => {
595+
console.error('Error fetching GitLab MRs:', {
596+
status: xhr.status,
597+
textStatus: textStatus,
598+
error: errorThrown
625599
});
626-
627-
// Process all issues
628-
Promise.all(issuesPromises)
629-
.then(results => {
630-
gitlabIssuesData = results.flat();
631-
console.log('[GitLab] Issues fetched (after flatten):', gitlabIssuesData);
632-
writeGitlabIssuesPrs();
633-
})
634-
.catch(error => {
635-
console.error('Error fetching GitLab issues:', error);
636-
Materialize.toast('Error fetching GitLab issues', 3000);
637-
});
638-
639-
// Process all merge requests
640-
Promise.all(mrsPromises)
641-
.then(results => {
642-
gitlabPrsReviewData = results.flat();
643-
console.log('[GitLab] Merge Requests fetched:', gitlabPrsReviewData.map(mr => ({ id: mr.id, title: mr.title, author: mr.author ? mr.author.username : undefined, project: mr.project ? mr.project.name : undefined })));
644-
writeGitlabPrsReviews();
645-
})
646-
.catch(error => {
647-
console.error('Error fetching GitLab merge requests:', error);
648-
Materialize.toast('Error fetching GitLab merge requests', 3000);
649-
});
600+
Materialize.toast('Error fetching GitLab merge requests.', 3000);
601+
},
602+
success: (mrs) => {
603+
console.log('[GitLab] MRs fetched:', mrs);
604+
gitlabPrsReviewData = mrs;
605+
writeGitlabPrsReviews();
650606
}
651607
});
652608

@@ -673,6 +629,20 @@ ${userReason}`;
673629
});
674630
}
675631

632+
function getProjectName(item) {
633+
// Get the project name from the full path
634+
if (item.references?.full) {
635+
return item.references.full.split('/').pop();
636+
}
637+
if (item.project?.path_with_namespace) {
638+
return item.project.path_with_namespace.split('/').pop();
639+
}
640+
if (item.project?.name) {
641+
return item.project.name;
642+
}
643+
return 'Unknown Project';
644+
}
645+
676646
function writeGitlabIssuesPrs() {
677647
if (!gitlabIssuesData) return;
678648

@@ -682,7 +652,7 @@ ${userReason}`;
682652
for (var i = 0; i < gitlabIssuesData.length; i++) {
683653
var item = gitlabIssuesData[i];
684654
var web_url = item.web_url;
685-
var project = gitlabProjectIdToName[item.project_id] || 'Unknown Project';
655+
var project = getProjectName(item);
686656
var title = item.title;
687657
var iid = item.iid;
688658
var li = '';
@@ -710,7 +680,7 @@ ${userReason}`;
710680
for (var i = 0; i < gitlabPrsReviewData.length; i++) {
711681
var item = gitlabPrsReviewData[i];
712682
var web_url = item.web_url;
713-
var project = gitlabProjectIdToName[item.project_id] || 'Unknown Project';
683+
var project = getProjectName(item);
714684
var title = item.title;
715685
var iid = item.iid;
716686

@@ -722,7 +692,7 @@ ${userReason}`;
722692
number: iid,
723693
html_url: web_url,
724694
title: title,
725-
state: item.state,
695+
state: item.state
726696
};
727697
gitlabPrsReviewDataProcessed[project].push(obj);
728698
}

0 commit comments

Comments
 (0)