Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: summary project output #288

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 21 additions & 15 deletions evergreen.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def main(): # pragma: no cover
raise ValueError(
"ORGANIZATION environment variable was not set. Please set it"
)
project_id = get_global_project_id(ghe, token, organization, project_id)
project_global_id = get_global_project_id(ghe, token, organization, project_id)

# Get the repositories from the organization, team name, or list of repositories
repos = get_repos_iterator(
Expand All @@ -83,7 +83,7 @@ def main(): # pragma: no cover
- **Organization:** {organization}
- **Follow Up Type:** {follow_up_type}
- **Dry Run:** {dry_run}
- **Enable Security Updates:** {enable_security_updates}
- **Enable Security Updates:** {enable_security_updates}\n
"""
# Add optional parameters to the summary
if project_id:
Expand Down Expand Up @@ -209,21 +209,20 @@ def main(): # pragma: no cover
):
enable_dependabot_security_updates(ghe, repo.owner, repo.name, token)

link = ""
if follow_up_type == "issue":
skip = check_pending_issues_for_duplicates(title, repo)
if not skip:
count_eligible += 1
body_issue = f"{body}\n\n```yaml\n# {dependabot_filename_to_use} \n{dependabot_file}\n```"
issue = repo.create_issue(title, body_issue)
link = issue.html_url
print(f"\tCreated issue {issue.html_url}")
if project_id:
summary_content += f"| {repo.full_name} | {'✅' if enable_security_updates else '❌'} | {follow_up_type} | [Link]({issue.html_url}) |\n"
if project_global_id:
issue_id = get_global_issue_id(
ghe, token, organization, repo.name, issue.number
)
link_item_to_project(ghe, token, project_id, issue_id)
print(f"\tLinked issue to project {project_id}")
link_item_to_project(ghe, token, project_global_id, issue_id)
print(f"\tLinked issue to project {project_global_id}")
else:
# Try to detect if the repo already has an open pull request for dependabot
skip = check_pending_pulls_for_duplicates(title, repo)
Expand All @@ -241,20 +240,27 @@ def main(): # pragma: no cover
dependabot_filename_to_use,
existing_config,
)
link = pull.html_url
print(f"\tCreated pull request {pull.html_url}")
if project_id:
summary_content += (
f"| {repo.full_name} | "
f"{'✅' if enable_security_updates else '❌'} | "
f"{follow_up_type} | "
f"[Link]({pull.html_url}) |\n"
)
if project_global_id:
pr_id = get_global_pr_id(
ghe, token, organization, repo.name, pull.number
)
response = link_item_to_project(ghe, token, project_id, pr_id)
response = link_item_to_project(
ghe, token, project_global_id, pr_id
)
if response:
print(f"\tLinked pull request to project {project_id}")
print(
f"\tLinked pull request to project {project_global_id}"
)
except github3.exceptions.NotFoundError:
print("\tFailed to create pull request. Check write permissions.")
continue
# Append the repository to the summary content
summary_content += f"| {repo.full_name} | {'✅' if enable_security_updates else '❌'} | {follow_up_type} | [Link]({link}) |\n"

print(f"Done. {str(count_eligible)} repositories were eligible.")
# Append the summary content to the GitHub step summary file
Expand Down Expand Up @@ -506,7 +512,7 @@ def get_global_pr_id(ghe, token, organization, repository, pr_number):
return None


def link_item_to_project(ghe, token, project_id, item_id):
def link_item_to_project(ghe, token, project_global_id, item_id):
"""
Links an item (issue or pull request) to a project in GitHub.
API: https://docs.github.com/en/graphql/guides/forming-calls-with-graphql
Expand All @@ -515,7 +521,7 @@ def link_item_to_project(ghe, token, project_id, item_id):
url = f"{api_endpoint}/graphql"
headers = {"Authorization": f"Bearer {token}"}
data = {
"query": f'mutation {{addProjectV2ItemById(input: {{projectId: "{project_id}", contentId: "{item_id}"}}) {{item {{id}}}}}}'
"query": f'mutation {{addProjectV2ItemById(input: {{projectId: "{project_global_id}", contentId: "{item_id}"}}) {{item {{id}}}}}}'
}

try:
Expand Down
Loading