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

removed release_notes_generator from prepare testing bucket #29204

Merged
merged 12 commits into from Sep 19, 2023
28 changes: 0 additions & 28 deletions .gitlab/ci/.gitlab-ci.instance-test.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .gitlab/ci/.gitlab-ci.on-push.yml
Expand Up @@ -119,7 +119,7 @@ validate-content-conf:
stage: prepare-testing-bucket
script:
- !reference [.download-demisto-conf]
- !reference [.create-release-notes-and-common-docs]

- section_start "Create or update content graph" --collapsed

- echo "Updating the content graph"
Expand Down
4 changes: 0 additions & 4 deletions .gitlab/ci/.gitlab-ci.sdk-nightly.yml
Expand Up @@ -65,10 +65,6 @@ demisto_sdk_nightly:check_idset_dependent_commands:
- demisto-sdk merge-id-sets -i1 $ARTIFACTS_FOLDER/id_set.json -i2 $ARTIFACTS_FOLDER/unified_id_set.json -o $ARTIFACTS_FOLDER/unified_id_set.json
- echo "successfully merged public and private ID sets"
- section_end "Merge public and private ID sets"
- section_start "Build Content Descriptor" --collapsed
- python3 Utils/release_notes_generator.py $CONTENT_VERSION $GIT_SHA1 $CI_BUILD_ID --output $ARTIFACTS_FOLDER/packs-release-notes.md --github-token $GITHUB_TOKEN
- cp content-descriptor.json $ARTIFACTS_FOLDER
- section_end "Build Content Descriptor"
- section_start "Common Server Documentation" --collapsed
- ./Documentation/commonServerDocs.sh
- section_end "Common Server Documentation"
Expand Down
1 change: 0 additions & 1 deletion .gitlab/ci/.gitlab-ci.yml
Expand Up @@ -66,7 +66,6 @@ include:
- local: .gitlab/ci/.gitlab-ci.global.yml
- local: .gitlab/ci/.gitlab-ci.on-push.yml
- local: .gitlab/ci/.gitlab-ci.bucket-upload.yml
- local: .gitlab/ci/.gitlab-ci.instance-test.yml
- local: .gitlab/ci/.gitlab-ci.sdk-nightly.yml
- local: .gitlab/ci/.gitlab-ci.miscellaneous.yml
- local: .gitlab/ci/.gitlab-ci.test-native-candidate.yml
Expand Down
2 changes: 1 addition & 1 deletion Tests/Marketplace/marketplace_services.py
Expand Up @@ -30,7 +30,7 @@
PackTags, PackIgnored, Changelog, BASE_PACK_DEPENDENCY_DICT, SIEM_RULES_OBJECTS, PackStatus, PACK_FOLDERS_TO_ID_SET_KEYS, \
CONTENT_ROOT_PATH, XSOAR_MP, XSIAM_MP, XPANSE_MP, TAGS_BY_MP, CONTENT_ITEM_NAME_MAPPING, \
ITEMS_NAMES_TO_DISPLAY_MAPPING, RN_HEADER_TO_ID_SET_KEYS
from Utils.release_notes_generator import aggregate_release_notes_for_marketplace, merge_version_blocks, construct_entities_block
from Utils.release_notes_handler import aggregate_release_notes_for_marketplace, merge_version_blocks, construct_entities_block
from Tests.scripts.utils import logging_wrapper as logging

PULL_REQUEST_PATTERN = '\(#(\d+)\)'
Expand Down Expand Up @@ -1144,7 +1144,7 @@
except Exception:
logging.exception(f"Failed in detecting modified files of {self._pack_name} pack")
finally:
return task_status, modified_rn_files_paths

Check failure on line 1147 in Tests/Marketplace/marketplace_services.py

View workflow job for this annotation

GitHub Actions / pre-commit

Ruff (SIM107)

Tests/Marketplace/marketplace_services.py:1147:13: SIM107 Don't use `return` in `try`-`except` and `finally`

def filter_modified_files_by_id_set(self, id_set: dict, modified_rn_files_paths: list, marketplace):
"""
Expand Down
@@ -1,17 +1,17 @@
import os
import re
import pytest
from Utils.release_notes_generator import (get_release_notes_dict,
generate_release_notes_summary,
get_pack_entities,
get_pack_version_from_path,
read_and_format_release_note,
merge_version_blocks,
EMPTY_LINES_REGEX,
get_new_entity_record,
construct_entities_block,
aggregate_release_notes,
aggregate_release_notes_for_marketplace)
from Utils.release_notes_handler import (get_release_notes_dict,
generate_release_notes_summary,
get_pack_entities,
get_pack_version_from_path,
read_and_format_release_note,
merge_version_blocks,
EMPTY_LINES_REGEX,
get_new_entity_record,
construct_entities_block,
aggregate_release_notes,
aggregate_release_notes_for_marketplace)

TEST_DATA_PATH = 'Tests/scripts/infrastructure_tests/tests_data/RN_tests_data'

Expand Down
103 changes: 0 additions & 103 deletions Utils/release_notes_generator.py → Utils/release_notes_handler.py
Expand Up @@ -3,14 +3,11 @@
import sys
import json
import glob
import argparse
from datetime import datetime
import logging

from packaging.version import Version
import requests
from demisto_sdk.commands.common.tools import run_command, get_dict_from_file
from Tests.scripts.utils.log_util import install_logging

PACKS_DIR = 'Packs'
DATE_FORMAT = '%d %B %Y'
Expand Down Expand Up @@ -419,103 +416,3 @@ def get_pack_version_suffix(pack_metadata):
elif is_community_supported_in_metadata(pack_metadata):
suffix = ' (Community Contributed)'
return suffix


def get_release_notes_draft(github_token, asset_id):
"""
if possible, download current release draft from content repository in github.

:param github_token: github token with push permission (in order to get the draft).
:param asset_id: content build's asset id.
:return: draft text (or empty string on error).
"""
if github_token is None:
logging.warning('Unable to download draft without github token.')
return ''

# Disable insecure warnings
import urllib3
urllib3.disable_warnings()
try:
res = requests.get('https://api.github.com/repos/demisto/content/releases',
verify=False, # guardrails-disable-line
headers={'Authorization': f'token {github_token}'})
except requests.exceptions.ConnectionError as exc:
logging.warning(f'Unable to get release draft, reason:\n{str(exc)}')
return ''

if res.status_code != 200:
logging.warning(f'Unable to get release draft ({res.status_code}), reason:\n{res.text}')
return ''

drafts = [release for release in res.json() if release.get('draft', False)]
if drafts:
if len(drafts) == 1:
draft_body = drafts[0]['body']
raw_asset = re.findall(r'Release Notes for version .* \((\d{5,}|xxxxx)\)', draft_body, re.IGNORECASE)
if raw_asset:
draft_body = draft_body.replace(raw_asset[0], asset_id)

return draft_body

logging.warning(f'Too many drafts to choose from ({len(drafts)}), skipping update.')

return ''


def create_content_descriptor(release_notes, version, asset_id, github_token):
# time format example 2017 - 06 - 11T15:25:57.0 + 00:00
current_date = datetime.now().strftime("%Y-%m-%dT%H:%M:%S.0+00:00")

content_descriptor = {
"installDate": "0001-01-01T00:00:00Z",
"assetId": int(asset_id),
"releaseNotes": release_notes,
"modified": current_date,
"ignoreGit": False,
"releaseDate": current_date,
"version": -1,
"release": version,
"id": ""
}

draft = get_release_notes_draft(github_token, asset_id)
if draft:
content_descriptor['releaseNotes'] = draft

with open('content-descriptor.json', 'w') as outfile:
json.dump(content_descriptor, outfile)


def main():
install_logging('Build_Content_Descriptor.log')
arg_parser = argparse.ArgumentParser()
arg_parser.add_argument('version', help='Release version')
arg_parser.add_argument('git_sha1', help='commit sha1 to compare changes with')
arg_parser.add_argument('asset_id', help='Asset ID')
arg_parser.add_argument('--output', help='Output file, default is ./packs-release-notes.md',
default='./packs-release-notes.md')
arg_parser.add_argument('--github-token', help='Github token')
args = arg_parser.parse_args()

new_packs = get_new_packs(args.git_sha1)
new_packs_release_notes = {}
new_packs_metadata = {}
for pack in new_packs:
pack_metadata = get_pack_metadata(pack)
pack_name = pack_metadata.get('name')
new_packs_release_notes[pack_name] = get_pack_entities(pack)
new_packs_metadata[pack_name] = pack_metadata

packs_metadata_dict = {}
modified_release_notes = get_all_modified_release_note_files(args.git_sha1)
modified_release_notes_dict, modified_packs_metadata = get_release_notes_dict(modified_release_notes)
packs_metadata_dict.update(new_packs_metadata)
packs_metadata_dict.update(modified_packs_metadata)
release_notes = generate_release_notes_summary(new_packs_release_notes, modified_release_notes_dict,
packs_metadata_dict, args.version, args.asset_id, args.output)
create_content_descriptor(release_notes, args.version, args.asset_id, args.github_token)


if __name__ == "__main__":
main()