示例#1
0
def changeset_abandon(cs_id):
    logger.info("Requested URL /changeset/%d/abandon [POST]", cs_id)
    changeset = Changeset.query.filter(Changeset.id == cs_id).first()
    if changeset is None:
        flash("Changeset {0} doesn't exist".format(cs_id), "error")
        logger.error("Changeset %d doesn't exist", cs_id)
        return redirect(url_for('index'))
    if not changeset.is_active():
        flash("Not active changeset cannot be abandoned", "error")
        logger.error("Changeset %d is not active and cannot be abandoned", cs_id)
        return redirect(url_for('changeset_info', cs_id=cs_id))
    if not (changeset.diff is None):
        flash("Changeset with diff attached to it cannot be abandoned", "error")
        logger.error("Changeset %d has a diff attached to it and cannot be abandoned", cs_id)
        return redirect(url_for('changeset_info', cs_id=cs_id))
    
    review = Review.query.filter(Review.id == changeset.review_id).first()
      
    changeset.status = "ABANDONED"
    db.session.commit()
    repo.hg_sync()
    repo.hg_bookmark(bookmark=changeset.bookmark, delete=True)
    if review.active_changeset is None:
        review_abandon(review.id)
    else:
        repo.hg_update(review.active_changeset.sha1)
        repo.hg_command("bookmark", changeset.bookmark)
    
    if changeset.sha1 in repo.hg_heads():
        repo.hg_close_branch(changeset.sha1)
    flash("Changeset '{title}' (SHA1: {sha1}) has been abandoned".format(title=changeset.title,
                                                                         sha1=changeset.sha1), "notice")
    repo.hg_push()                                                                     
    return redirect(url_for("review_info", review_id=changeset.review_id))
示例#2
0
def review_abandon(review_id):
    logger.info("Requested URL /review/%d/abandon [POST]", review_id)
    review = Review.query.filter(Review.id == review_id).first()
    if review is None:
        flash("Review {0} doesn't exist".format(review_id), "error")
        logger.error("Review %d doesn't exist", review_id)
        return redirect(url_for("index"))
    review.status = "ABANDONED"
    review.abandoned_date = datetime.datetime.utcnow()
    Head.query.filter(Head.review_id == review.id).update({'review_id': None})
    db.session.commit()
    repo.hg_sync()
    #repo.hg_bookmark(bookmark=review.bookmark, delete=True)
    #repo.hg_push()
    heads = repo.hg_heads()
    for c in review.changesets:
        if c.sha1 in heads:
            repo.hg_close_branch(c.sha1)
    flash("Review has been abandoned", "notice")
    return redirect(url_for('changes_active'))