def test_get_last_release(self, mocker): mocker.patch('demisto_sdk.commands.common.tools.run_command', return_value='1.2.3\n4.5.6\n3.2.1\n20.0.0') tag = get_last_release_version() assert tag == '20.0.0'
def get_new_and_modified_integration_files(git_sha1): """Return 2 lists - list of new integrations and list of modified integrations since the commit of the git_sha1. Args: git_sha1 (str): The git sha of the commit against which we will run the 'git diff' command. Returns: (tuple): Returns a tuple of two lists, the file paths of the new integrations and modified integrations. """ # get changed yaml files (filter only added and modified files) tag = get_last_release_version() file_validator = FilesValidator() change_log = run_command('git diff --name-status {}'.format(git_sha1)) modified_files, added_files, removed_files, old_format_files = file_validator.get_modified_files(change_log, tag) all_integration_regexes = YML_INTEGRATION_REGEXES all_integration_regexes.extend([INTEGRATION_REGEX, PACKS_INTEGRATION_REGEX, BETA_INTEGRATION_REGEX]) new_integration_files = [ file_path for file_path in added_files if checked_type(file_path, all_integration_regexes) ] modified_integration_files = [ file_path for file_path in modified_files if isinstance(file_path, str) and checked_type(file_path, all_integration_regexes) ] return new_integration_files, modified_integration_files
def main(): 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('server_version', help='Server version') arg_parser.add_argument('--github-token', help='Github token') args = arg_parser.parse_args() tag = get_last_release_version() print('Last release version: {}'.format(tag)) # get changed yaml/json files (filter only relevant changed files) file_validator = FilesValidator() try: change_log = run_command('git diff --name-status {}'.format( args.git_sha1), exit_on_error=False) except RuntimeError: print_error( 'Unable to get the SHA1 of the commit in which the version was released. This can happen if your ' 'branch is not updated with origin master. Merge from origin master and, try again.\n' 'If you\'re not on a fork, run "git merge origin/master".\n' 'If you are on a fork, first set https://github.com/demisto/content to be ' 'your upstream by running "git remote add upstream https://github.com/demisto/content". After ' 'setting the upstream, run "git fetch upstream", and then run "git merge upstream/master". Doing ' 'these steps will merge your branch with content master as a base.' ) sys.exit(1) else: modified_files, added_files, removed_files, _ = file_validator.get_modified_files( change_log) modified_files, added_files, removed_files = filter_packagify_changes( modified_files, added_files, removed_files, tag=tag) for file_path in added_files: create_file_release_notes('A', file_path) for file_path in modified_files: create_file_release_notes('M', file_path) for file_path in removed_files: # content entities are only yml/json files. ignore all the rest. if file_path.endswith('.yml') or file_path.endswith('.json'): handle_deleted_file(file_path, tag) # join all release notes res = [] beta_res = [] missing_release_notes = False for key in RELEASE_NOTES_ORDER: value = RELEASE_NOTE_GENERATOR[key] ans, beta_ans = value.generate_release_notes(args.server_version) if ans is None or value.is_missing_release_notes: missing_release_notes = True if ans: res.append(ans) if beta_ans: beta_res.append(beta_ans) release_notes = "\n---\n".join(res) beta_release_notes = "\n---\n".join(beta_res) create_content_descriptor(args.version, args.asset_id, release_notes, args.github_token, beta_rn=beta_release_notes) if missing_release_notes: print_error( "Error: some release notes are missing. See previous errors.") sys.exit(1)