Skip to content

Commit

Permalink
Add an option to skip ignore if labels or milestones already exist
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorentClarret committed Dec 27, 2024
1 parent 237b1f2 commit d8fcc28
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
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):
"""
Creates a label in the given GitHub repository.
"""
return self._repository.create_label(name, color, description)
import github

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):
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

0 comments on commit d8fcc28

Please sign in to comment.