@@ -58,57 +58,123 @@ jobs:
5858 return [];
5959 }
6060 }
61- async function getMonthCommitStats(since, until) {
62- const commits = await github.paginate(github.rest.repos.listCommits, {
63- owner: context.repo.owner,
64- repo: context.repo.repo,
65- since,
66- until,
67- per_page: 100,
68- });
69-
70- const contributors = new Set();
71- const filesChanged = new Set();
72- let totalAdditions = 0;
73- let totalDeletions = 0;
7461
75- for (const commit of commits.slice(0, 50)) {
76- if (commit.author) {
77- contributors.add(commit.author.login);
62+ // Get commit statistics - properly separated like GitHub Pulse
63+ async function getMonthCommitStats(since, until) {
64+ console.log(`=== GETTING COMMITS BETWEEN ${since} AND ${until} ===`);
65+
66+ try {
67+ // Get the default branch name first
68+ const repo = await github.rest.repos.get({
69+ owner: context.repo.owner,
70+ repo: context.repo.repo,
71+ });
72+ const defaultBranch = repo.data.default_branch;
73+ console.log(`*** DEFAULT BRANCH: ${defaultBranch} ***`);
74+
75+ // Get ALL commits from ALL branches (no sha filter)
76+ console.log('*** FETCHING ALL BRANCH COMMITS ***');
77+ const allBranchCommits = await github.paginate(github.rest.repos.listCommits, {
78+ owner: context.repo.owner,
79+ repo: context.repo.repo,
80+ since,
81+ until,
82+ per_page: 100,
83+ });
84+
85+ console.log(`*** FOUND ${allBranchCommits.length} COMMITS ACROSS ALL BRANCHES ***`);
86+
87+ // Get commits from MAIN branch only
88+ console.log('*** FETCHING MAIN BRANCH COMMITS ***');
89+ const mainBranchCommits = await github.paginate(github.rest.repos.listCommits, {
90+ owner: context.repo.owner,
91+ repo: context.repo.repo,
92+ sha: defaultBranch,
93+ since,
94+ until,
95+ per_page: 100,
96+ });
97+
98+ console.log(`*** FOUND ${mainBranchCommits.length} COMMITS ON ${defaultBranch} ***`);
99+
100+ // Process ALL branch commits for total authors and line changes
101+ const allAuthors = new Set();
102+ let totalAdditions = 0;
103+ let totalDeletions = 0;
104+
105+ console.log('*** PROCESSING ALL BRANCH COMMITS FOR AUTHORS ***');
106+ for (const commit of allBranchCommits) {
107+ if (commit.author && commit.author.login) {
108+ allAuthors.add(commit.author.login);
109+ }
110+
111+ // Get detailed stats for first 50 commits to avoid rate limits
112+ if (allBranchCommits.indexOf(commit) < 50) {
113+ try {
114+ const commitDetail = await github.rest.repos.getCommit({
115+ owner: context.repo.owner,
116+ repo: context.repo.repo,
117+ ref: commit.sha,
118+ });
119+
120+ totalAdditions += commitDetail.data.stats?.additions || 0;
121+ totalDeletions += commitDetail.data.stats?.deletions || 0;
122+ } catch (error) {
123+ console.log(`Error getting commit detail: ${error.message}`);
124+ }
125+ }
78126 }
79-
80- try {
81- const commitDetail = await github.rest.repos.getCommit({
82- owner: context.repo.owner,
83- repo: context.repo.repo,
84- ref: commit.sha,
85- });
86-
87- if (commitDetail.data.files) {
88- commitDetail.data.files.forEach(file => {
89- filesChanged.add(file.filename);
127+
128+ console.log(`*** FOUND ${allAuthors.size} UNIQUE AUTHORS ***`);
129+ console.log(`*** AUTHORS: ${Array.from(allAuthors).join(', ')} ***`);
130+
131+ // Process MAIN branch commits for main-specific file changes
132+ let mainFileChanges = 0;
133+
134+ for (const commit of mainBranchCommits.slice(0, 30)) {
135+ try {
136+ const commitDetail = await github.rest.repos.getCommit({
137+ owner: context.repo.owner,
138+ repo: context.repo.repo,
139+ ref: commit.sha,
90140 });
141+
142+ mainFileChanges += commitDetail.data.files?.length || 0;
143+ } catch (error) {
144+ console.log(`Error getting main commit detail: ${error.message}`);
91145 }
92-
93- totalAdditions += commitDetail.data.stats?.additions || 0;
94- totalDeletions += commitDetail.data.stats?.deletions || 0;
95- } catch (error) {
96- console.log(`Error getting commit details: ${error.message}`);
97146 }
147+
148+ const result = {
149+ totalCommitsAllBranches: allBranchCommits.length,
150+ totalCommitsMain: mainBranchCommits.length,
151+ totalAuthors: allAuthors.size,
152+ authorsList: Array.from(allAuthors),
153+ filesChangedMain: mainFileChanges,
154+ linesAdded: totalAdditions,
155+ linesRemoved: totalDeletions,
156+ netLines: totalAdditions - totalDeletions,
157+ };
158+
159+ console.log('*** FINAL RESULT ***', JSON.stringify(result, null, 2));
160+ return result;
161+
162+ } catch (error) {
163+ console.log('*** ERROR GETTING COMMIT STATS ***', error.message);
164+ return {
165+ totalCommitsAllBranches: 0,
166+ totalCommitsMain: 0,
167+ totalAuthors: 0,
168+ authorsList: [],
169+ filesChangedMain: 0,
170+ linesAdded: 0,
171+ linesRemoved: 0,
172+ netLines: 0,
173+ };
98174 }
99-
100- return {
101- totalCommits: commits.length,
102- uniqueContributors: contributors.size,
103- contributorsList: Array.from(contributors),
104- filesChanged: filesChanged.size,
105- linesAdded: totalAdditions,
106- linesRemoved: totalDeletions,
107- netLines: totalAdditions - totalDeletions,
108- };
109175 }
110176
111- // Get PR statistics for a specific month
177+ // Get pull request statistics
112178 async function getMonthPRStats(since, until) {
113179 const allPRs = await github.paginate(github.rest.pulls.list, {
114180 owner: context.repo.owner,
@@ -216,7 +282,6 @@ jobs:
216282 });
217283 existingFileSha = existingFile.data.sha;
218284 } catch (error) {
219- // File doesn't exist, that's okay
220285 console.log(`File ${file.path} doesn't exist yet, creating new file`);
221286 }
222287
@@ -229,7 +294,6 @@ jobs:
229294 branch: targetBranch
230295 };
231296
232- // Add SHA if file exists
233297 if (existingFileSha) {
234298 params.sha = existingFileSha;
235299 }
@@ -244,7 +308,7 @@ jobs:
244308
245309 // Main execution
246310 try {
247- console.log('Gathering repository data for last 12 months... ');
311+ console.log('*** STARTING MONTHLY REPORT GENERATION *** ');
248312
249313 // Get current branch
250314 let targetBranch;
@@ -256,15 +320,14 @@ jobs:
256320 console.log(`Using branch: ${targetBranch}`);
257321 }
258322
259- // Gather data for last 12 months - use previous month as latest
323+ // Gather data for last 12 months
260324 const monthlyDataArray = [];
261325 const now = new Date();
262326
263327 for (let i = 12; i >= 1; i--) {
264328 const monthStart = new Date(now.getFullYear(), now.getMonth() - i, 1);
265329 const monthEnd = new Date(now.getFullYear(), now.getMonth() - i + 1, 0);
266330
267- // Debug the date calculation
268331 console.log(`Month ${i}: ${monthStart.toLocaleDateString()} to ${monthEnd.toLocaleDateString()}`);
269332
270333 const monthRange = {
@@ -293,16 +356,14 @@ jobs:
293356 console.log('Generating and committing SVG charts...');
294357 await commitChartsToRepo(monthlyDataArray, targetBranch);
295358
296- // Get language stats for current month
359+ // Get language stats
297360 const languageStats = await getLanguageStats();
298361
299- // Use latest month for Mattermost (should be July 2025)
362+ // Use latest month for Mattermost
300363 const latestMonthData = monthlyDataArray[monthlyDataArray.length - 1];
301- console.log(`Latest month data for Mattermost:`, JSON.stringify(latestMonthData, null, 2));
302- console.log(`Stats object:`, JSON.stringify(latestMonthData.stats, null, 2));
303- console.log(`PR Stats object:`, JSON.stringify(latestMonthData.prStats, null, 2));
364+ console.log(`*** LATEST MONTH FOR MATTERMOST ***`, JSON.stringify(latestMonthData, null, 2));
304365
305- // Post to Mattermost using correct property names
366+ // Post to Mattermost
306367 const mattermostPayload = {
307368 text: `📊 **${latestMonthData.month} Repository Activity**`,
308369 attachments: [{
0 commit comments