-
Notifications
You must be signed in to change notification settings - Fork 0
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
Sourcery refactored main branch #1
Conversation
path = 'templates/' + templateFile | ||
path = f'templates/{templateFile}' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function applyTemplate
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
def fromJson(text): | ||
tmp = json.loads(text, object_hook=lambda d: label( | ||
d['name'], d['description'], d['color'])) | ||
def fromJson(self): | ||
tmp = json.loads( | ||
self, | ||
object_hook=lambda d: label(d['name'], d['description'], d['color']), | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function label.fromJson
refactored with the following changes:
- The first argument to instance methods should be
self
(instance-method-first-arg-name
)
cmd = 'gh label {}'.format(self.option) | ||
repo = '-R {}/{}'.format(owner, repo) | ||
cmd = f'gh label {self.option}' | ||
repo = f'-R {owner}/{repo}' | ||
|
||
append = str() | ||
|
||
if self.option == 'create': | ||
label = '\"{}\" --description \"{}\" --color {}'.format( | ||
self.name, self.label.description, self.label.color.replace("#", "")) | ||
append = '-f {}'.format(label) | ||
label = f'\"{self.name}\" --description \"{self.label.description}\" --color {self.label.color.replace("#", "")}' | ||
append = f'-f {label}' | ||
elif self.option == 'edit': | ||
nameChanged = self.name != self.label.name | ||
append = '\"{}\" --description \"{}\" --color {}'.format( | ||
self.name, self.label.description, self.label.color.replace("#", "")) | ||
append = f'\"{self.name}\" --description \"{self.label.description}\" --color {self.label.color.replace("#", "")}' | ||
if nameChanged: | ||
append += ' --name \"{}\"'.format(self.label.name) | ||
append += f' --name \"{self.label.name}\"' | ||
elif self.option == 'delete': | ||
append = '\"{}\" --yes'.format(self.name) | ||
append = f'\"{self.name}\" --yes' | ||
|
||
fullCommand = '{} {} {}'.format(cmd, repo, append) | ||
fullCommand = f'{cmd} {repo} {append}' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function action.execute
refactored with the following changes:
- Replace call to format with f-string [×8] (
use-fstring-for-formatting
)
repo = '-R {}/{}'.format(owner, repo) | ||
repo = f'-R {owner}/{repo}' | ||
condition = '--json name,description,color' | ||
jq = '--jq \".[]\"' | ||
|
||
fullCommand = '{} {} {} {}'.format(cmd, repo, condition, jq) | ||
fullCommand = f'{cmd} {repo} {condition} {jq}' | ||
|
||
process = os.popen(fullCommand) | ||
output = process.read().splitlines() | ||
process.close() | ||
|
||
labels = [label.fromJson(x) for x in output if x != ''] | ||
|
||
return labels | ||
return [label.fromJson(x) for x in output if x != ''] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function getLabels
refactored with the following changes:
- Replace call to format with f-string [×2] (
use-fstring-for-formatting
) - Inline variable that is immediately returned (
inline-immediately-returned-variable
)
def build(path): | ||
if os.path.exists(path): | ||
with open(path, 'r') as file: | ||
def build(self): | ||
if os.path.exists(self): | ||
with open(self, 'r') as file: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function labelsTemplate.build
refactored with the following changes:
- The first argument to instance methods should be
self
(instance-method-first-arg-name
)
process = os.popen('{} {} {} {}'.format(cmd, owner, json, jq)) | ||
process = os.popen(f'{cmd} {owner} {json} {jq}') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function labelsTemplate.applyToRepos
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
for x in templateLabelsNames: | ||
if not currentLabelsNames.__contains__(x): | ||
actions.append( | ||
action('create', x, self.labels[templateLabelsNames.index(x)])) | ||
|
||
actions.extend( | ||
action('create', x, self.labels[templateLabelsNames.index(x)]) | ||
for x in templateLabelsNames | ||
if not currentLabelsNames.__contains__(x) | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function labelsTemplate.apply
refactored with the following changes:
- Replace a for append loop with list extend (
for-append-to-extend
)
Branch
main
refactored by Sourcery.If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.
See our documentation here.
Run Sourcery locally
Reduce the feedback loop during development by using the Sourcery editor plugin:
Review changes via command line
To manually merge these changes, make sure you're on the
main
branch, then run:Help us improve this pull request!