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 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
31 changes: 27 additions & 4 deletions tasks/libs/ciproviders/github_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,14 +519,37 @@ 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="", exist_ok=False):
"""
Creates a label in the given GitHub repository.
"""
return self._repository.create_label(name, color, description)

def create_milestone(self, title):
self._repository.create_milestone(title)
try:
return self._repository.create_label(name, color, description)
except GithubException as e:
if not (
e.status == 422
and len(e.data["errors"]) == 1
and e.data["errors"][0]["code"] == "already_exists"
and exist_ok
):
raise e

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

try:
return self._repository.create_milestone(title)
except GithubException as e:
if not (
e.status == 422
and len(e.data["errors"]) == 1
and e.data["errors"][0]["code"] == "already_exists"
and exist_ok
):
raise e

def create_release(self, tag, message, draft=True):
return self._repository.create_git_release(
Expand Down
11 changes: 2 additions & 9 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}',
exist_ok=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 @@ -1216,14 +1216,7 @@ def update_current_milestone(ctx, major_version: int = 7, upstream="origin"):
next.devel = False

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), exist_ok=True)

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