def meta_add_desc_command(ctx, description): current = ctx.obj["INCIDENT"] current.cname = description current.store() log.success("{incident} description set successfully", incident=current.identifier)
def vcs_rollback_command(ctx, commit): current = ctx.obj["INCIDENT"] # Store tags and relations before rollback previous_tags = set(current.tags) previous_relations = set(current.meta.get("relations", set())) repository.rollback(current, commit) current.load() # Store state after rollback and recover temporarily current_tags = set(current.tags) current_relations = set(current.meta.get("relations", set())) current.tags = previous_tags current.meta["relations"] = previous_relations for added_tag in current_tags.difference(previous_tags): log.info("ROLLBACK: Added tag #{}".format(added_tag)) current.add_tag(added_tag) for removed_tag in previous_tags.difference(current_tags): log.info("ROLLBACK: Removed tag #{}".format(removed_tag)) current.add_tag(removed_tag) for added_relation in current_relations.difference(previous_relations): log.info("ROLLBACK: Added relation with {}".format(added_relation)) current.add_relation(added_relation) for removed_relation in previous_relations.difference(current_relations): log.info("ROLLBACK: Removed relation with {}".format(removed_relation)) current.remove_relation(removed_relation) # Reload once again (not necessary, but left in case of further changes) current.load() log.success("Rollbacked successfully!")
def meta_add_tag_command(ctx, tag): current = ctx.obj["INCIDENT"] tag = current.add_tag(tag) if tag is None: log.error("Invalid tag name! Must start with letter and contain only letters, digits, underscores or dashes") ctx.abort() current.store() log.success("Tagged as {tag}", tag="#" + tag)
def switch_command(ctx, incident_id): current = incident.choose_incident(incident_id, allow_current=False) if current is None: log.error("No incident found.") ctx.abort() incident.set_current_incident(current) log.success("Switched to {incident}", incident=current.identifier) ctx.obj["INCIDENT"] = current
def custom_attribute_handler(value): current = ctx.obj["INCIDENT"] current.remove_meta(name, value) current.store() if value is None: log.success("Removed custom attribute {name}", name=name) else: log.success("Removed {value} from custom attribute {name}", value=value, name=name)
def open_command(ctx, incident_id): current = incident.choose_incident(incident_id) if current is None: log.error("No incident found.") ctx.abort() if not current.closed: log.error("Incident is opened yet") ctx.abort() current.closed = False current.store() log.success("Incident {incident} opened", incident=current.identifier) ctx.obj["INCIDENT"] = current
def new_command(ctx, desc, created_at, owner): current = incident.get_current_incident() if not log.QUIET_MODE and current is not None and not current.closed: log.warning("Current incident {current} is opened.", current=current.identifier) if not click.confirm("Do you really want to create new incident?"): ctx.abort() created_at = created_at and parse(created_at) current = incident.Incident(cname=desc, created_on=created_at, owner=owner) current.store() incident.set_current_incident(current) log.success("New incident created {incident}", incident=current.identifier) ctx.obj["INCIDENT"] = current
def custom_attribute_handler(value, as_list, as_set): current = ctx.obj["INCIDENT"] if as_list: current.add_meta(name, value, type=list) elif as_set: current.add_meta(name, value, type=set) else: current.add_meta(name, value) current.store() log.success("Added {value} to custom attribute {name}", value=value, name=name)
def meta_del_rel_command(ctx, related): current = ctx.obj["INCIDENT"] with_inc = incident.choose_incident(related, allow_current=False) if with_inc is None: log.error("No incident found.") ctx.abort() current.remove_relation(with_inc) with_inc.remove_relation(current) current.store() with_inc.store() log.success("Unmarked {incident} as related with {related}", incident=current.identifier, related=with_inc.identifier)
def meta_add_rel_command(ctx, related): current = ctx.obj["INCIDENT"] with_inc = incident.choose_incident(related, allow_current=False) if with_inc is None: log.error("No incident found.") ctx.abort() if with_inc.uuid == current.uuid: log.error("Incidents are the same object - relation can't be added") ctx.abort() current.add_relation(with_inc) with_inc.add_relation(current) current.store() with_inc.store() log.success("Marked {incident} as related with {related}", incident=current.identifier, related=with_inc.identifier)
def vcs_commit_command(ctx, message): current = ctx.obj["INCIDENT"] changes = repository.uncommitted_files(current) default_message = "(empty)" if not changes: log.error("No pending changes!") ctx.abort() if not message: if not log.QUIET_MODE: log.warning( "Empty commit message. Please provide commit description.") message = click.prompt("Description:", default=default_message) else: message = default_message repository.commit(current, message) log.echo("Changed files:", ignore_short=True) for path in changes: log.echo("* {path}", path=path, ignore_short=True) log.success("Changes committed successfully!")
def vcs_ignore_command(ctx): current = ctx.obj["INCIDENT"] readme_path = os.path.join(current.dirpath, ".gitignore") click.edit(filename=readme_path) log.success("Note successfully saved in {path}", path=readme_path)
def meta_note_command(ctx): current = ctx.obj["INCIDENT"] readme_path = os.path.join(current.dirpath, "README") click.edit(filename=readme_path) log.success("Note successfully saved in {path}", path=readme_path)
def meta_remove_tag_command(ctx, tag): current = ctx.obj["INCIDENT"] current.remove_tag(tag) current.store() log.success("Untagged as {tag}", tag="#" + tag)