Skip to content

Support for copying label descriptions #9

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 7 additions & 3 deletions githublabelscopy/githublabelscopy.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
to another.

Usage:
github-labels-copy [--login=<login> | --token=<token>] [-crm]
github-labels-copy [--login=<login> | --token=<token>] [-crms]
(--load=<file> | SOURCE) (--dump | DESTINATION)
github-labels-copy (-h | --help)
github-labels-copy --version
Expand All @@ -28,6 +28,8 @@
repository.
-m Modify labels existing in both repositories but with a
different color.
-s Modify descriptions existing in both repositories but
with different content.

"""

Expand Down Expand Up @@ -77,8 +79,10 @@ def label_copy():
if args['-r']:
labels.deleteBad()
if args['-m']:
labels.updateWrong()
if not args['-c'] and not args['-r'] and not args['-m']:
labels.updateWrongColors()
if args['-s']:
labels.updateWrongDescriptions()
if not args['-c'] and not args['-r'] and not args['-m'] and not args['-s']:
labels.fullCopy()

if args['--dump']:
Expand Down
57 changes: 37 additions & 20 deletions githublabelscopy/labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ def _identify(self, token=None, login=None):
def setSrcRepo(self, repository):
self.src_repo = self.github.get_repo(repository)
src_original_labels = self.src_repo.get_labels()
self.src_labels = {label.name: label.color
self.src_labels = {label.name: {'color': label.color, 'description': label.description}
for label in src_original_labels}

def setDstRepo(self, repository):
self.dst_repo = self.github.get_repo(repository)
self.dst_original_labels = self.dst_repo.get_labels()
self.dst_labels = {label.name: label.color
self.dst_labels = {label.name: {'color': label.color, 'description': label.description}
for label in self.dst_original_labels}

def load(self, filename):
Expand All @@ -46,38 +46,54 @@ def listLabels(self):

def getMissing(self):
"Get missing labels from source repository into destination."
return {name: color for name, color in self.src_labels.items()
if name not in self.dst_labels.keys()}
return {label_name: label_data for label_name, label_data in self.src_labels.items()
if label_name not in self.dst_labels.keys()}

def getWrong(self):
def getWrongColor(self):
"Get labels with wrong color in destination repository from source."
return {name: color for name, color in self.src_labels.items()
if name in self.dst_labels.keys() and
color != self.dst_labels[name]}
return {label_name: label_data for label_name, label_data in self.src_labels.items()
if label_name in self.dst_labels.keys() and
label_data['color'] != self.dst_labels[label_name]['color']}

def getWrongDescription(self):
"Get labels with wrong description in destination repository from source."
return {label_name: label_data for label_name, label_data in self.src_labels.items()
if label_name in self.dst_labels.keys() and
label_data['description'] != self.dst_labels[label_name]['description']}

def getBad(self):
"Get labels from destination repository not in source."
return {name: color for name, color in self.dst_labels.items()
if name not in self.src_labels.keys()}
return {label_name: label_data for label_name, label_data in self.dst_labels.items()
if label_name not in self.src_labels.keys()}

def createMissing(self):
"Create all missing labels from source repository in destination."
missings = self.getMissing()
self._labels.update(missings)
if not self._dumpMode:
for name, color in missings.items():
print("Creating {}".format(name))
self.dst_repo.create_label(name, color)
for label_name, label_data in missings.items():
print("Creating {}".format(label_name))
self.dst_repo.create_label(label_name, label_data['color'], label_data['description'])

def updateWrong(self):
wrongs = self.getWrong()
def updateWrongColor(self):
wrongs = self.getWrongColor()
self._labels.update(wrongs)
if not self._dumpMode:
for name, color in wrongs.items():
print("Updating {}".format(name))
for label_name, label_data in wrongs.items():
print("Updating {}".format(label_name))
working_label = next((x for x in self.dst_original_labels
if x.name == name), None)
working_label.edit(name, color)
if x.name == label_name), None)
working_label.edit(label_name, label_data['color'], working_label.description)

def updateWrongDescription(self):
wrongs = self.getWrongDescription()
self._labels.update(wrongs)
if not self._dumpMode:
for label_name, label_data in wrongs.items():
print("Updating {}".format(label_name))
working_label = next((x for x in self.dst_original_labels
if x.name == label_name), None)
working_label.edit(label_name, working_label.color, label_data['description'])

def deleteBad(self):
bads = self.getBad()
Expand All @@ -91,5 +107,6 @@ def deleteBad(self):

def fullCopy(self):
self.createMissing()
self.updateWrong()
self.updateWrongColor()
self.updateWrongDescription()
self.deleteBad()
2 changes: 1 addition & 1 deletion requirements
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
docopt==0.6.2
PyGithub==1.34
PyGithub==1.55
PyYAML==3.12
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
packages=['githublabelscopy'],
long_description=open('README.rst').read(),
install_requires=[
'PyGithub==1.34',
'PyGithub==1.55',
'docopt==0.6.2',
'PyYAML==3.12'
],
Expand Down