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

Add an option to skip ignore if labels or milestones already exist #32532

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
23 changes: 19 additions & 4 deletions tasks/libs/ciproviders/github_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,14 +519,29 @@ def get_token_from_app(app_id_env='GITHUB_APP_ID', pkey_env='GITHUB_KEY_B64'):
auth_token = integration.get_access_token(install_id)
print(auth_token.token)

def create_label(self, name, color, description=""):
def create_label(self, name, color, description="", ignore_existing=False):
FlorentClarret marked this conversation as resolved.
Show resolved Hide resolved
"""
Creates a label in the given GitHub repository.
"""
return self._repository.create_label(name, color, description)
import github
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already import GithubException above so this should not be necessary.

from github import Auth, Github, GithubException, GithubIntegration, GithubObject, PullRequest


def create_milestone(self, title):
self._repository.create_milestone(title)
try:
return self._repository.create_label(name, color, description)
except github.GithubException as e:
if not (e.status == 422 and ignore_existing):
FlorentClarret marked this conversation as resolved.
Show resolved Hide resolved
raise e

def create_milestone(self, title, ignore_existing=False):
"""
Creates a milestone in the given GitHub repository.
"""
import github

try:
return self._repository.create_milestone(title)
except github.GithubException as e:
if not (e.status == 422 and ignore_existing):
raise e

def create_release(self, tag, message, draft=True):
return self._repository.create_git_release(
Expand Down
10 changes: 2 additions & 8 deletions tasks/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,7 @@ def create_release_branches(ctx, base_directory="~/dd", major_version: int = 7,
f'backport/{release_branch}',
BACKPORT_LABEL_COLOR,
f'Automatically create a backport PR to {release_branch}',
ignore_existing=True,
)

# Step 2 - Create PRs with new settings in datadog-agent repository
Expand Down Expand Up @@ -1207,7 +1208,6 @@ def update_current_milestone(ctx, major_version: int = 7, upstream="origin"):
"""
Create a PR to bump the current_milestone in the release.json file
"""
import github

gh = GithubAPI()

Expand All @@ -1217,13 +1217,7 @@ def update_current_milestone(ctx, major_version: int = 7, upstream="origin"):

print(f"Creating the {next} milestone...")

try:
gh.create_milestone(str(next))
except github.GithubException as e:
if e.status == 422:
print(f"Milestone {next} already exists")
else:
raise e
gh.create_milestone(str(next), ignore_existing=True)

with agent_context(ctx, get_default_branch(major=major_version)):
milestone_branch = f"release_milestone-{int(time.time())}"
Expand Down
Loading