Skip to content

Commit 8f2fc23

Browse files
committed
making same as pr
1 parent ae04201 commit 8f2fc23

File tree

1 file changed

+104
-121
lines changed

1 file changed

+104
-121
lines changed

src/scripts/scrumHelper.js

Lines changed: 104 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
console.log('Script loaded, adapter exists:', !!window.emailClientAdapter);
22
var enableToggle = true;
33
var gitlabProjectIdToName = {};
4-
var gitlabOrgFilter = '';
54
function allIncluded(outputTarget = 'email') {
65
console.log('allIncluded called with outputTarget:', outputTarget);
76
console.log('Current window context:', window.location.href);
@@ -58,7 +57,6 @@ function allIncluded(outputTarget = 'email') {
5857
'yesterdayContribution',
5958
'userReason',
6059
'platform',
61-
'gitlabOrgFilter',
6260
],
6361
(items) => {
6462
console.log("Storage items received:", items);
@@ -151,10 +149,6 @@ function allIncluded(outputTarget = 'email') {
151149
if (!items.userReason) {
152150
userReason = 'No Blocker at the moment';
153151
}
154-
155-
if (items.gitlabOrgFilter) {
156-
gitlabOrgFilter = items.gitlabOrgFilter;
157-
}
158152
},
159153
);
160154
}
@@ -565,128 +559,117 @@ ${userReason}`;
565559
}
566560

567561
function fetchGitlabData() {
568-
// Get the organization/group filter from storage (if any)
569-
chrome.storage.local.get(['gitlabOrgFilter'], function (orgItems) {
570-
gitlabOrgFilter = orgItems.gitlabOrgFilter || '';
571-
572-
var projectsUrl = `https://gitlab.com/api/v4/users/${gitlabUsername}/projects?per_page=100`;
573-
console.log('[GitLab] Fetching projects for user:', gitlabUsername, 'URL:', projectsUrl);
574-
575-
$.ajax({
576-
dataType: 'json',
577-
type: 'GET',
578-
url: projectsUrl,
579-
error: (xhr, textStatus, errorThrown) => {
580-
console.error('Error fetching GitLab projects:', {
581-
status: xhr.status,
582-
textStatus: textStatus,
583-
error: errorThrown
584-
});
585-
Materialize.toast('Error fetching GitLab projects. Please check your username.', 3000);
586-
},
587-
success: (projects) => {
588-
// Build projectId-to-name map
589-
gitlabProjectIdToName = {};
590-
projects.forEach(p => {
591-
gitlabProjectIdToName[p.id] = p.name;
592-
});
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);
593565

594-
// Filter projects by organization/group if filter is set
595-
let filteredProjects = projects;
596-
if (gitlabOrgFilter && gitlabOrgFilter.trim() !== '') {
597-
filteredProjects = projects.filter(p => p.path_with_namespace.toLowerCase().startsWith(gitlabOrgFilter.toLowerCase() + '/'));
598-
console.log('[GitLab] Filtering projects by org/group:', gitlabOrgFilter, 'Filtered:', filteredProjects.map(p => p.path_with_namespace));
599-
}
600-
console.log('[GitLab] Projects fetched:', filteredProjects.map(p => ({ id: p.id, name: p.name, path_with_namespace: p.path_with_namespace })));
601-
if (!filteredProjects || filteredProjects.length === 0) {
602-
Materialize.toast('No GitLab projects found for this user and organization/group', 3000);
603-
return;
604-
}
566+
$.ajax({
567+
dataType: 'json',
568+
type: 'GET',
569+
url: projectsUrl,
570+
error: (xhr, textStatus, errorThrown) => {
571+
console.error('Error fetching GitLab projects:', {
572+
status: xhr.status,
573+
textStatus: textStatus,
574+
error: errorThrown
575+
});
576+
Materialize.toast('Error fetching GitLab projects. Please check your username.', 3000);
577+
},
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+
}
605584

606-
// Fetch issues and MRs for each filtered project
607-
var projectIds = filteredProjects.map(p => p.id);
608-
var issuesPromises = [];
609-
var mrsPromises = [];
610-
611-
projectIds.forEach(projectId => {
612-
// Fetch issues
613-
var issuesUrl = `https://gitlab.com/api/v4/projects/${projectId}/issues?author_username=${gitlabUsername}&created_after=${getStartOfDayISO(startingDate)}&created_before=${getEndOfDayISO(endingDate)}&per_page=100`;
614-
console.log(`[GitLab] Fetching issues for project ${projectId}:`, issuesUrl);
615-
issuesPromises.push(
616-
$.ajax({
617-
dataType: 'json',
618-
type: 'GET',
619-
url: issuesUrl,
620-
success: function (data) {
621-
console.log(`[GitLab][DEBUG] Raw issues response for project ${projectId}:`, data);
622-
return data;
623-
},
624-
error: function (xhr, textStatus, errorThrown) {
625-
console.error(`[GitLab][ERROR] Issues API error for project ${projectId}:`, xhr.status, textStatus, errorThrown, xhr.responseText);
626-
return [];
627-
}
628-
})
629-
);
630-
631-
// Fetch merge requests
632-
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`;
633-
console.log(`[GitLab] Fetching MRs for project ${projectId}:`, mrsUrl);
634-
mrsPromises.push(
635-
$.ajax({
636-
dataType: 'json',
637-
type: 'GET',
638-
url: mrsUrl
639-
})
640-
);
641-
});
585+
// After fetching projects:
586+
projects.forEach(p => {
587+
gitlabProjectIdToName[p.id] = p.name;
588+
});
642589

643-
// Process all issues
644-
Promise.all(issuesPromises)
645-
.then(results => {
646-
gitlabIssuesData = results.flat();
647-
console.log('[GitLab] Issues fetched (after flatten):', gitlabIssuesData);
648-
writeGitlabIssuesPrs();
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+
}
649612
})
650-
.catch(error => {
651-
console.error('Error fetching GitLab issues:', error);
652-
Materialize.toast('Error fetching GitLab issues', 3000);
653-
});
654-
655-
// Process all merge requests
656-
Promise.all(mrsPromises)
657-
.then(results => {
658-
gitlabPrsReviewData = results.flat();
659-
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_id ? gitlabProjectIdToName[mr.project_id] : undefined })));
660-
writeGitlabPrsReviews();
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
661623
})
662-
.catch(error => {
663-
console.error('Error fetching GitLab merge requests:', error);
664-
Materialize.toast('Error fetching GitLab merge requests', 3000);
665-
});
666-
}
667-
});
624+
);
625+
});
668626

669-
// Fetch GitLab user data
670-
var userUrl = `https://gitlab.com/api/v4/users?username=${gitlabUsername}`;
671-
console.log('[GitLab] Fetching user data:', userUrl);
672-
$.ajax({
673-
dataType: 'json',
674-
type: 'GET',
675-
url: userUrl,
676-
error: (xhr, textStatus, errorThrown) => {
677-
console.error('Error fetching GitLab user data:', {
678-
status: xhr.status,
679-
textStatus: textStatus,
680-
error: errorThrown
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);
681637
});
682-
},
683-
success: (data) => {
684-
if (data && data.length > 0) {
685-
gitlabUserData = data[0];
686-
console.log('[GitLab] User data:', gitlabUserData);
687-
}
688-
},
689-
});
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+
});
650+
}
651+
});
652+
653+
// Fetch GitLab user data
654+
var userUrl = `https://gitlab.com/api/v4/users?username=${gitlabUsername}`;
655+
console.log('[GitLab] Fetching user data:', userUrl);
656+
$.ajax({
657+
dataType: 'json',
658+
type: 'GET',
659+
url: userUrl,
660+
error: (xhr, textStatus, errorThrown) => {
661+
console.error('Error fetching GitLab user data:', {
662+
status: xhr.status,
663+
textStatus: textStatus,
664+
error: errorThrown
665+
});
666+
},
667+
success: (data) => {
668+
if (data && data.length > 0) {
669+
gitlabUserData = data[0];
670+
console.log('[GitLab] User data:', gitlabUserData);
671+
}
672+
},
690673
});
691674
}
692675

0 commit comments

Comments
 (0)