Skip to content

Commit b63b8b1

Browse files
authored
feat: enhance GitHub Action summary with detailed repository updates (#280)
1 parent b599bcb commit b63b8b1

File tree

3 files changed

+85
-0
lines changed

3 files changed

+85
-0
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,9 @@ jobs:
206206
env:
207207
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
208208
ORGANIZATION: <YOUR_ORGANIZATION_GOES_HERE>
209+
210+
- name: Post evergreen job summary
211+
run: cat summary.md >> $GITHUB_STEP_SUMMARY
209212
```
210213

211214
#### Advanced
@@ -249,6 +252,9 @@ jobs:
249252
TITLE: "Add dependabot configuration"
250253
BODY: "Please add this dependabot configuration so that we can keep the dependencies in this repo up to date and secure. for help, contact XXX"
251254
CREATED_AFTER_DATE: ${{ env.one_week_ago }}
255+
256+
- name: Post evergreen job summary
257+
run: cat summary.md >> $GITHUB_STEP_SUMMARY
252258
```
253259

254260
#### Using GitHub app
@@ -281,6 +287,9 @@ jobs:
281287
ORGANIZATION: your_organization
282288
UPDATE_EXISTING: True
283289
GROUP_DEPENDENCIES: True
290+
291+
- name: Post evergreen job summary
292+
run: cat summary.md >> $GITHUB_STEP_SUMMARY
284293
```
285294

286295
## Local usage without Docker

evergreen.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,28 @@ def main(): # pragma: no cover
7777
organization, team_name, repository_list, github_connection
7878
)
7979

80+
# Setting up the action summary content
81+
summary_content = f"""
82+
## 🚀 Job Summary
83+
- **Organization:** {organization}
84+
- **Follow Up Type:** {follow_up_type}
85+
- **Dry Run:** {dry_run}
86+
- **Enable Security Updates:** {enable_security_updates}
87+
"""
88+
# Add optional parameters to the summary
89+
if project_id:
90+
project_link = f"https://github.com/orgs/{organization}/projects/{project_id}"
91+
summary_content += f"- **Project ID:** [{project_id}]({project_link})\n"
92+
if batch_size:
93+
summary_content += f"- **Batch Size:** {batch_size}\n"
94+
95+
# Add the updated repositories table header
96+
summary_content += (
97+
"\n\n## 📋 Updated Repositories\n\n"
98+
"| Repository | 🔒 Security Updates Enabled | 🔄 Follow Up Type | 🔗 Link |\n"
99+
"| --- | --- | --- | --- |\n"
100+
)
101+
80102
# Iterate through the repositories and open an issue/PR if dependabot is not enabled
81103
count_eligible = 0
82104
for repo in repos:
@@ -187,12 +209,14 @@ def main(): # pragma: no cover
187209
):
188210
enable_dependabot_security_updates(ghe, repo.owner, repo.name, token)
189211

212+
link = ""
190213
if follow_up_type == "issue":
191214
skip = check_pending_issues_for_duplicates(title, repo)
192215
if not skip:
193216
count_eligible += 1
194217
body_issue = f"{body}\n\n```yaml\n# {dependabot_filename_to_use} \n{dependabot_file}\n```"
195218
issue = repo.create_issue(title, body_issue)
219+
link = issue.html_url
196220
print(f"\tCreated issue {issue.html_url}")
197221
if project_id:
198222
issue_id = get_global_issue_id(
@@ -217,6 +241,7 @@ def main(): # pragma: no cover
217241
dependabot_filename_to_use,
218242
existing_config,
219243
)
244+
link = pull.html_url
220245
print(f"\tCreated pull request {pull.html_url}")
221246
if project_id:
222247
pr_id = get_global_pr_id(
@@ -228,6 +253,12 @@ def main(): # pragma: no cover
228253
except github3.exceptions.NotFoundError:
229254
print("\tFailed to create pull request. Check write permissions.")
230255
continue
256+
# Append the repository to the summary content
257+
summary_content += f"| {repo.full_name} | {'✅' if enable_security_updates else '❌'} | {follow_up_type} | [Link]({link}) |\n"
258+
259+
print(f"Done. {str(count_eligible)} repositories were eligible.")
260+
# Append the summary content to the GitHub step summary file
261+
append_to_github_summary(summary_content)
231262

232263
print(f"Done. {str(count_eligible)} repositories were eligible.")
233264

@@ -496,5 +527,14 @@ def link_item_to_project(ghe, token, project_id, item_id):
496527
return None
497528

498529

530+
def append_to_github_summary(content, summary_file="summary.md"):
531+
"""
532+
Append content to the GitHub step summary file
533+
"""
534+
if summary_file:
535+
with open(summary_file, "a", encoding="utf-8") as f:
536+
f.write(content + "\n")
537+
538+
499539
if __name__ == "__main__":
500540
main() # pragma: no cover

test_evergreen.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import github3
88
import requests
99
from evergreen import (
10+
append_to_github_summary,
1011
check_existing_config,
1112
check_pending_issues_for_duplicates,
1213
check_pending_pulls_for_duplicates,
@@ -738,5 +739,40 @@ def test_check_existing_config_without_existing_config(self):
738739
self.assertIsNone(result)
739740

740741

742+
class TestAppendToGithubSummary(unittest.TestCase):
743+
"""Test the append_to_github_summary function in evergreen.py"""
744+
745+
@patch("builtins.open", new_callable=unittest.mock.mock_open)
746+
def test_append_to_github_summary_with_file(self, mock_file):
747+
"""Test that content is appended to the specified summary file."""
748+
content = "Test summary content"
749+
summary_file = "summary.md"
750+
751+
append_to_github_summary(content, summary_file)
752+
753+
mock_file.assert_called_once_with(summary_file, "a", encoding="utf-8")
754+
mock_file().write.assert_called_once_with(content + "\n")
755+
756+
@patch("builtins.open", new_callable=unittest.mock.mock_open)
757+
def test_append_to_github_summary_without_summary_file(self, mock_file):
758+
"""Test that content is not written when summary_file is None or empty."""
759+
content = "Test summary content"
760+
summary_file = ""
761+
762+
append_to_github_summary(content, summary_file)
763+
764+
mock_file.assert_not_called()
765+
766+
@patch("builtins.open", new_callable=unittest.mock.mock_open)
767+
def test_append_to_github_summary_with_default_file(self, mock_file):
768+
"""Test that content is appended to the default summary file when summary_file is not provided."""
769+
content = "Test summary content"
770+
771+
append_to_github_summary(content)
772+
773+
mock_file.assert_called_once_with("summary.md", "a", encoding="utf-8")
774+
mock_file().write.assert_called_once_with(content + "\n")
775+
776+
741777
if __name__ == "__main__":
742778
unittest.main()

0 commit comments

Comments
 (0)