Skip to content

Commit c7f90d5

Browse files
authored
Merge pull request #40 from chrheg/issue-37
Enhancing Issue comments
2 parents dcd15d3 + 04184d9 commit c7f90d5

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Below are the allowed configuration options:
4141
| `EXEMPT_REPOS` | False | "" | These repositories will be exempt from this action considering them for dependabot enablement. ex: If my org is set to `github` then I might want to exempt a few of the repos but get the rest by setting `EXEMPT_REPOS` to ``github/evergreen,github/contributors` |
4242
| `TYPE` | False | pull | Type refers to the type of action you want taken if this workflow determines that dependabot could be enabled. Valid values are `pull` or `issue`.|
4343
| `TITLE` | False | "Enable Dependabot" | The title of the issue or pull request that will be created if dependabot could be enabled. |
44-
| `BODY` | False | "Dependabot could be enabled for this repository. Please enable it by merging this pull request so that we can keep our dependencies up to date and secure." | The body of the issue or pull request that will be created if dependabot could be enabled. |
44+
| `BODY` | False | **Pull Request:** "Dependabot could be enabled for this repository. Please enable it by merging this pull request so that we can keep our dependencies up to date and secure." **Issue:** "Please update the repository to include a Dependabot configuration file. This will ensure our dependencies remain updated and secure.Follow the guidelines in [creating Dependabot configuration files](https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file) to set it up properly.Here's an example of the code:" | The body of the issue or pull request that will be created if dependabot could be enabled. |
4545
| `COMMIT_MESSAGE` | False | "Create dependabot.yaml" | The commit message for the pull request that will be created if dependabot could be enabled. |
4646
| `CREATED_AFTER_DATE` | False | none | If a value is set, this action will only consider repositories created on or after this date for dependabot enablement. This is useful if you want to only consider newly created repositories. If I set up this action to run weekly and I only want to scan for repos created in the last week that need dependabot enabled, then I would set `CREATED_AFTER_DATE` to 7 days ago. That way only repositories created after 7 days ago will be considered for dependabot enablement. If not set or set to nothing, all repositories will be scanned and a duplicate issue/pull request may occur. Ex: 2023-12-31 for Dec. 31st 2023 |
4747
| `PROJECT_ID` | False | "" | If set, this will assign the issue or pull request to the project with the given ID. ( The project ID on GitHub can be located by navigating to the respective project and observing the URL's end.) **The `ORGANIZATION` variable is required** |

env.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,23 @@ def get_env_vars() -> (
9999
title = "Enable Dependabot"
100100

101101
body = os.getenv("BODY")
102-
# make sure that body is a string with less than 65536 characters
103-
if body:
104-
if len(body) > 65536:
105-
raise ValueError("BODY environment variable is too long")
106-
else:
107-
body = "Dependabot could be enabled for this repository. \
108-
Please enable it by merging this pull request \
109-
so that we can keep our dependencies up to date and secure."
102+
if body and len(body) > 65536:
103+
raise ValueError("BODY environment variable is too long")
104+
105+
if not body:
106+
default_bodies = {
107+
"pull": "Dependabot could be enabled for this repository. \
108+
Please enable it by merging this pull request so that we can keep our dependencies up to date and secure.",
109+
"issue": (
110+
"Please update the repository to include a Dependabot configuration file.\n"
111+
"This will ensure our dependencies remain updated and secure.\n"
112+
"Follow the guidelines in [creating Dependabot configuration files]"
113+
"(https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file) "
114+
"to set it up properly.\n\n"
115+
"Here's an example of the code:"
116+
),
117+
}
118+
body = body = default_bodies[follow_up_type]
110119

111120
commit_message = os.getenv("COMMIT_MESSAGE")
112121
if commit_message:

evergreen.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,14 @@ def main(): # pragma: no cover
9595
skip = check_pending_issues_for_duplicates(title, repo)
9696
if not skip:
9797
count_eligible += 1
98-
issue = repo.create_issue(title, body)
98+
body_issue = (
99+
body
100+
+ "\n\n```yaml\n"
101+
+ "# .github/dependabot.yml\n"
102+
+ dependabot_file
103+
+ "\n```"
104+
)
105+
issue = repo.create_issue(title, body_issue)
99106
print("\tCreated issue " + issue.html_url)
100107
if project_id:
101108
issue_id = get_global_issue_id(

0 commit comments

Comments
 (0)