<commit_before>#!/usr/bin/env python
import getpass
from tools import *
from jira_api import JiraApi
from bitbucket_api import BitbucketApi
import subprocess

print(styled('Release maker. Created by <NAME>.', bcolors.HEADER))

login = input_req('Логин Jira: ')
password = getpass.getpass()

jira_api = JiraApi(login, password)

permissions = jira_api.get_my_permissions()
if len(permissions) == 0:
    exit(styled('Нет доступа в Jira', bcolors.WARNING))


projects = jira_api.get_projects()
if len(projects) == 0:
    exit(styled('Нет доступных проектов', bcolors.WARNING))

print('Выберите проект')
for i in range(0, len(projects)):
    print(str(i) + ') ' + projects[i]['name'])

while True:
    project_key = int(input('Введите номер: '))
    if len(projects) > project_key >= 0:
        break

project = projects[project_key]
print(styled(project['name'], bcolors.BOLD))

versions = jira_api.get_project_versions(project['key'])
versions = [version for version in versions if not version['released']]
for i in range(0, len(versions)):
    print(str(i) + ') ' + versions[i]['name'])

if len(versions) > 1:
    while True:
        version_key = int(input('Введите номер: '))
        if len(versions) > version_key >= 0:
            break
    version = versions[version_key]
else:
    version = versions[0]

print(styled('Релиз ' + version['name'], bcolors.BOLD))

jql = 'project = ' + project['key'] + ' AND fixVersion = ' + version['name']
issues = jira_api.get_issues(jql)
if len(issues) == 0:
    exit(styled('Задачи релиза не найдены', bcolors.WARNING))

bitbucket_api = BitbucketApi(login, password)

projects = bitbucket_api.get_projects()
if len(projects) == 0:
    exit(styled('Проекты в bitbucket не найдены', bcolors.WARNING))

print('Выберите проект в Bitbucket:')
for i in range(0, len(projects)):
    print(str(i) + ') ' + projects[i]['name'])

while True:
    project_key = int(input('Введите номер: '))
    if len(projects) > project_key >= 0:
        break
    project = projects[project_key]

print(styled(project['name'], bcolors.BOLD))

repos = bitbucket_api.get_project_repos(project['key'])
if len(repos) == 0:
    exit(styled('Нет репозитариев в проекте'))

print('Выберите репозитарий')
for i in range(0, len(repos)):
    print(str(i) + ') ' + repos[i]['name'])

while True:
    repo_key = int(input('Введите номер: '))
    if len(repos) > repo_key >= 0:
        break

repo = repos[repo_key]
print(styled(repo['name'], bcolors.BOLD))

params = {
    'until': 'qa',
    'since': 'master',
    'merges': 'exclude',
    'limit': 10000
}
commits = bitbucket_api.get_commits(project['key'], repo['slug'], params)
if len(commits) == 0:
    exit(styled('В выбранном репозитарии нет коммитов', bcolors.WARNING))


issue_keys = [issue['key'] for issue in issues]
release_commits = []
for commit in commits:
    valid = False
    try:
        for jira in commit['properties']['jira-key']:
            if jira in issue_keys:
                valid = True
    except KeyError:
        continue

    if valid:
        release_commits.append(commit['id'])

release_commits = list(reversed(release_commits))
subprocess.call(['git', 'fetch'])
subprocess.call(['git', 'checkout', 'master'])
subprocess.call(['git', 'pull', 'origin', 'master'])<commit_msg>Change message, print commits count by issue tasks before start making release branch<commit_after>#!/usr/bin/env python
import getpass
from tools import *
from jira_api import JiraApi
from bitbucket_api import BitbucketApi
import subprocess
import math

print(styled('Release maker. Created by <NAME>.', bcolors.HEADER))

login = input_req('Jira login: ')
password = <PASSWORD>()

jira_api = JiraApi(login, password)

permissions = jira_api.get_my_permissions()
if len(permissions) == 0:
    exit(styled('Login or password is incorrect', bcolors.WARNING))


projects = jira_api.get_projects()
if len(projects) == 0:
    exit(styled('Projects not found', bcolors.WARNING))

print('Select project')
for i in range(0, len(projects)):
    print(str(i) + ') ' + projects[i]['name'])

while True:
    project_key = int(input('Enter number: '))
    if len(projects) > project_key >= 0:
        break

project = projects[project_key]
print(styled(project['name'], bcolors.BOLD))

versions = jira_api.get_project_versions(project['key'])
if len(versions) == 0:
    exit(styled('Fix versions for selected project not found'))

versions = [version for version in versions if not version['released']]
for i in range(0, len(versions)):
    print(str(i) + ') ' + versions[i]['name'])

while True:
    version_key = int(input('Enter number: '))
    if len(versions) > version_key >= 0:
        break

version = versions[version_key]
print(styled('Selected fix version ' + version['name'], bcolors.BOLD))

jql = 'project = ' + project['key'] + ' AND fixVersion = ' + version['name']
issues = jira_api.get_issues(jql)
if len(issues) == 0:
    exit(styled('Issues for selected fix version not found', bcolors.WARNING))

bitbucket_api = BitbucketApi(login, password)

projects = bitbucket_api.get_projects()
if len(projects) == 0:
    exit(styled('Projects in BitBucket not found', bcolors.WARNING))

print('Select BitBucket project:')
for i in range(0, len(projects)):
    print(str(i) + ') ' + projects[i]['name'])

while True:
    project_key = int(input('Enter number: '))
    if len(projects) > project_key >= 0:
        break
    project = projects[project_key]

print(styled(project['name'], bcolors.BOLD))

repos = bitbucket_api.get_project_repos(project['key'])
if len(repos) == 0:
    exit(styled('Repositories in selected project not found'))

print('Select repository')
for i in range(0, len(repos)):
    print(str(i) + ') ' + repos[i]['name'])

while True:
    repo_key = int(input('Enter number: '))
    if len(repos) > repo_key >= 0:
        break

repo = repos[repo_key]
print(styled(repo['name'], bcolors.BOLD))

params = {
    'until': 'qa',
    'since': 'master',
    'merges': 'exclude',
    'limit': 10000
}
commits = bitbucket_api.get_commits(project['key'], repo['slug'], params)
if len(commits) == 0:
    exit(styled('Commits in selected repository not found', bcolors.WARNING))


issue_keys = [issue['key'] for issue in issues]
release_commits = []
commits_count = {}
for commit in commits:
    valid = False
    try:
        for jira in commit['properties']['jira-key']:
            if jira in issue_keys:
                if jira not in commits_count:
                    commits_count[jira] = 0

                valid = True
                commits_count[jira] += 1
    except KeyError:
        continue

    if valid:
        release_commits.append(commit['id'])

print(styled('Release commits count:', bcolors.HEADER))
print('-' * 49)
print('|' + ' ' * 6 + 'Jira issue' + ' ' * 7 + '|' + ' ' * 5 + 'Commits count' + ' ' * 5 + '|')
print('-' * 49)
for jira in commits_count:
    count = commits_count[jira]
    jlspace = int(math.ceil((23 - len(jira)) / 2))
    jrspace = int(math.floor((23 - len(jira)) / 2))

    count = str(count)
    clspace = int(math.ceil((23 - len(count)) / 2))
    crspace = int(math.floor((23 - len(count)) / 2))

    print('|' + ' ' * jlspace + jira + ' ' * jrspace + '|' + ' ' * clspace + count + ' ' * crspace + '|')
    print('-' * 49)

release_commits = list(reversed(release_commits))
approve = input_req("Make release branch uses this commits [y/n]?\n")
if approve == 'n' or approve == 'N':
    exit(styled('Making release branch canceled', bcolors.WARNING))

subprocess.call(['git', 'fetch'])
subprocess.call(['git', 'checkout', 'master'])
subprocess.call(['git', 'pull', 'origin', 'master'])
{'fraction_non_alphanumeric': 0.15883668903803133, 'fraction_numerical': 0.008553757073299119, 'mean_word_length': 4.117845117845118, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6352776', 'n_tokens_mistral': 2661, 'n_tokens_neox': 2575, 'n_words': 628}