Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
bb4e981
Merge remote-tracking branch 'upstream/master'
Sep 26, 2019
3cc00fd
Merge remote-tracking branch 'upstream/master'
Sep 26, 2019
12b19b5
A new Tempo method
Oct 3, 2019
8193283
Tempo: add team member
Oct 3, 2019
8ee5f04
Merge branch 'master' of https://github.com/gonchik/atlassian-python-api
Oct 3, 2019
16beefa
Bugfix
Oct 4, 2019
086c53d
Merge remote-tracking branch 'upstream/master'
Oct 4, 2019
911fac0
Merge conflicts
Oct 4, 2019
fd0cf22
Set workload method
Oct 23, 2019
f190a27
Bump version
Oct 23, 2019
0add3ae
Sync with upstream
Oct 27, 2019
c530690
Merge remote-tracking branch 'upstream/master'
Oct 28, 2019
359c1ee
Organize the imports
Oct 28, 2019
0e4e922
Polish
Oct 28, 2019
1fbfcc9
Bump version
Nov 13, 2019
91bf302
Add LFS info fetcher
Nov 13, 2019
141ff2a
Merge conflict
Nov 13, 2019
fa1a454
Git fix conflict
Nov 19, 2019
047486c
Merge remote-tracking branch 'upstream/master'
Nov 22, 2019
0aacfc1
Typo
Nov 23, 2019
05eea34
Merge branch 'master' of https://github.com/gonchik/atlassian-python-api
Nov 23, 2019
ce26890
Consolidate the Jira8 module into main
Nov 23, 2019
61b8fba
Add reindex methods
Nov 23, 2019
cf3e80e
Project related methods
Nov 23, 2019
a950ffb
Add update setup.py
Nov 23, 2019
952ca9e
Rename variables and polish to be in PEP-8
Nov 23, 2019
7f523cb
Polish
Nov 23, 2019
f83adac
Add Jira issue regex matcher
Nov 23, 2019
9f1ef7c
Add static method
Nov 23, 2019
96b0894
Add static method
Nov 23, 2019
2dbdffd
[Jira] fix upload attachment methods
Nov 24, 2019
df1f8b0
Hotfix for jira8 class
Nov 25, 2019
b386821
Hotfix for jira8 class
Nov 25, 2019
cd3a649
Merge branch 'master' into master
gonchik Nov 25, 2019
2ec6c9f
fix conflict
Nov 29, 2019
1eda694
Merge remote-tracking branch 'upstream/master'
Dec 1, 2019
9452aaa
Add the cookie file supports
Dec 22, 2019
2bfd724
Add methods for Confluence docs
Dec 22, 2019
6a3cee2
Polish comment
Jan 8, 2020
0f779da
Merge remote-tracking branch 'upstream/master'
Jan 8, 2020
497da1c
Add priority scheme configs
Jan 10, 2020
95f9c30
Merge remote-tracking branch 'upstream/master'
Jan 17, 2020
319e6aa
Bitbucket: example for clean branches
Jan 20, 2020
13457b2
Merge remote-tracking branch 'upstream/master'
Jan 22, 2020
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
20 changes: 10 additions & 10 deletions atlassian/jira.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,16 @@ def user_update_username(self, old_username, new_username):
data = {"name": new_username}
return self.user_update(old_username, data=data)

def user_update_email(self, username, email):
"""
Update user email for new domain changes
:param username:
:param email:
:return:
"""
data = {'name': username, 'emailAddress': email}
return self.user_update(username, data=data)

def user_create(self, username, email, display_name, password=None, notification=None):
"""
Create a user in Jira
Expand Down Expand Up @@ -219,16 +229,6 @@ def user_update_or_create_property_through_rest_point(self, username, key, value
params = {'username': username, 'property': key, 'value': value}
return self.get(url, params=params)

def user_update_email(self, username, email):
"""
Update user email for new domain changes
:param username:
:param email:
:return:
"""
data = {'name': username, 'emailAddress': email}
return self.user_update(username, data=data)

def user_deactivate(self, username):
"""
Disable user
Expand Down
95 changes: 95 additions & 0 deletions examples/stash-clean-jira-branches.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
from atlassian import Jira
from atlassian import Stash
from var import config
import logging
import time

PROJECT_KEY = 'PROJ'
REPOS = ['repo1', 'repo2']
ACCEPTED_ISSUE_STATUSES = ["Closed", "Verified"]
EXCLUDE_REPO_RULES = config.exclude_parameters
LAST_COMMIT_CONDITION_IN_DAYS = 75
ATLASSIAN_USER = config.JIRA_LOGIN
ATLASSIAN_PASSWORD = config.JIRA_PASSWORD

logging.basicConfig(level=logging.ERROR)
jira = Jira(
url=config.JIRA_URL,
username=ATLASSIAN_USER,
password=ATLASSIAN_PASSWORD)

stash = Stash(
url=config.STASH_URL,
username=ATLASSIAN_USER,
password=ATLASSIAN_PASSWORD
)

flag = True
time_now = int(time.time()) * 1000
delta_for_time_ms = LAST_COMMIT_CONDITION_IN_DAYS * 24 * 60 * 60 * 1000
commit_info_key = "com.atlassian.bitbucket.server.bitbucket-branch:latest-commit-metadata"
out_going_pull_request = "com.atlassian.bitbucket.server.bitbucket-ref-metadata:outgoing-pull-request-metadata"
branch_related_issues = "com.atlassian.bitbucket.server.bitbucket-jira:branch-list-jira-issues"


def is_can_removed_branch(branch_candidate):
branch_id_name = branch_candidate.get('id')
# Just exclude exist mainstream branches
if any(x in branch_id_name for x in EXCLUDE_REPO_RULES):
print(branch.get('displayId') + " in exclusion list")
return False
# skip default branch maybe DevOps made configs in ui
if branch_candidate.get('isDefault'):
print(branch.get('displayId') + " is default")
return False
pull_request_info = ((branch_candidate.get('metadata') or {}).get(out_going_pull_request) or {})
if pull_request_info.get('pullRequest') is not None or (pull_request_info.get('open') or 0) > 0:
print(branch.get('displayId') + " has open PR")
return False
# skip branches without pull request info
if pull_request_info is None or len(pull_request_info) == 0:
print(branch.get('displayId') + " without pull request info")
# return False

author_time_stamp = branch_candidate.get('metadata').get(commit_info_key).get('authorTimestamp')
# check latest commit info
if time_now - author_time_stamp < delta_for_time_ms:
print(branch.get('displayId') + " is too early to remove")
return False

# check issues statuses
exclude = False
issues_in_metadata = branch_candidate.get('metadata').get(branch_related_issues)
for issue in issues_in_metadata:
if jira.get_issue_status(issue.get('key')) not in ACCEPTED_ISSUE_STATUSES:
print(branch.get('displayId') + " related issue has not Resolution ")
return False
# so branch can be removed
return True


if __name__ == '__main__':
DRY_RUN = False
log = open("candidate_to_remove.csv", "w")
log.write("'Branch name', 'Latest commit', 'Related issues has Resolution'\n")
for repository in REPOS:
step = 0
limit = 10
while flag:
branches = stash.get_branches(PROJECT_KEY, repository, start=step * limit, limit=limit,
order_by='ALPHABETICAL')
if len(branches) == 0:
flag = False
break
for branch in branches:
display_id = branch['displayId']
committer_time_stamp = branch.get('metadata').get(commit_info_key).get('committerTimestamp') / 1000
last_date_commit = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(committer_time_stamp))
if is_can_removed_branch(branch):
if not DRY_RUN:
stash.delete_branch(project=PROJECT_KEY, repository=repository, name=display_id,
end_point=branch['latestCommit'])
log.write("{},{},{}\n".format(display_id, last_date_commit, True))
step += 1
log.close()
print("Done")