8

私は自分の会社のアクセス制御を gerrit で設定していますが、現在の内部プロセスでは、ピア レビュー担当者とコーダーがクロスオーバーしています (彼らは同じグループの人々である傾向があります)。また、コードのピア レビューを行い、問題がなければ提出するレビュアーを 1 人に限定したいと考えています。

デフォルトのセットアップでは、+2: Looks good to me, approvedオプションを使用するすべてのユーザーが自分のコードをピア レビューできます。

作成者が自分のコードをレビューできないようにしながら、他のコードを完全にレビューできるようにする方法はありますか? アクセス制御グループのセットアップまたは権限のセットアップで、どのような種類の除外作成者も見つけることができませんでした。

4

5 に答える 5

4

Gerrit クックブックの例 8は、作成者が自分の変更を確認することを厳密に禁止するものではありませんが、提出する前に他の誰かが +2 する必要があります。

于 2013-05-01T16:42:53.503 に答える
2

これは私にとってはうまくいきますが、簡単なハックです:

  • +1 の数を設定して、手動送信の +2 としてカウントできます
  • 必要に応じて、十分な+1票で自動的に送信します
  • オプションで、集計の目的で +1 票に対抗するものとして -1 票をカウントします
  • オプションで、アップローダー自身の +1 を無視します (作成者に対するチェックを好むかもしれませんが、私は行っていません)

以前の回答を微調整したので、mysql サーバーを使用しているとは限りません。

ログ ファイルを、通常のログ ローテーションの対象となる場所 (おそらく ../logs/comment-added.log) に移動することをお勧めします。

構成可能なビットを前面に出そうとしました。このファイルをコメントフックと呼び、$gerrit_root/hooks に置き、chmod 755 などにします。フックが sql インターフェイスを使用できるように、管理者グループにロボット ユーザーを設定します (十分な数の +1 があるものについて +2 をコメントします)。

#!/usr/bin/perl
#
# comment-hook for a +2 approval from a simple quorum of +1 votes.
#
# Licence: Public domain. All risk is yours; if it breaks, you get to keep both pieces.

$QUORUM = 2; # Total number of +1 votes causing a +2
$PLEBIANS = 'abs(value) < 2'; # or 'value = 1' to ignore -1 unvotes
$AUTO_SUBMIT_ON_QUORACY = '--submit'; # or '' for none
$AND_IGNORE_UPLOADER = 'and uploader_account_id != account_id'; # or '' to let uploaders votes count

$GERRIT_SSH_PORT = 29418;
$SSH_PRIVATE_KEY = '/home/gerrit2/.ssh/id_rsa';
$SSH_USER_IN_ADMIN_GROUP = 'devuser';

# Hopefully you shouldn't need to venture past here.

$SSH = "ssh -i $SSH_PRIVATE_KEY -p $GERRIT_SSH_PORT $SSH_USER_IN_ADMIN_GROUP\@localhost";

$LOG = "/home/gerrit2/hooks/log.comment-added";
open LOG, ">>$LOG" or die;

sub count_of_relevant_votes {
        # Total selected code review votes for this commit
        my $relevance = shift;
        $query = "
                select sum(value) from patch_sets, patch_set_approvals
                where patch_sets.change_id = patch_set_approvals.change_id
                and patch_sets.patch_set_id = patch_set_approvals.patch_set_id
                and revision = '$V{commit}'
                and category_id = 'CRVW'
                and $relevance
                $AND_IGNORE_UPLOADER
                ;";
        $command = "$SSH \"gerrit gsql -c \\\"$query\\\"\"";
        #print LOG "FOR... $command\n";
        @lines = qx($command);
        chomp @lines;
        #print LOG "GOT... ", join("//", @lines), "\n";
        # 0=headers 1=separators 2=data 3=count and timing.
        return $lines[2];
}

sub response {
        my $review = shift;
        return "$SSH 'gerrit review --project=\"$V{project}\" $review $V{commit}'";
}

# ######################
# Parse options

$key='';
while ( $_ = shift @ARGV ) {
        if (/^--(.*)/) {
                $key = $1;
        }
        else {
                $V{$key} .= " " if exists $V{$key};
                $V{$key} .= $_;
        }
}
#print LOG join("\n", map { "$_ = '$V{$_}'" } keys %V), "\n";

# ######################
# Ignore my own comments

$GATEKEEPER="::GATEKEEPER::";
if ($V{comment} =~ /$GATEKEEPER/) {
        # print LOG localtime() . "$V{commit}: Ignore $GATEKEEPER comments\n";
        exit 0;
}

# ######################
# Forbear to analyse anything already +2'd

$submittable = count_of_relevant_votes('value = 2');
if ($submittable > 0) {
        # print LOG "$V{commit} Already +2'd by someone or something.\n";
        exit 0;
}

# ######################
# Look for a consensus amongst qualified voters.

$plebicite = count_of_relevant_votes($PLEBIANS);

#if ($V{comment} =~ /TEST:(\d)/) {
#        $plebicite=$1;
#}

# ######################
# If there's a quorum, approve and submit.

if ( $plebicite >= $QUORUM ) {
        $and_submitting = ($AUTO_SUBMIT_ON_QUORACY ? " and submitting" : "");
        $review = " --code-review=+2 --message=\"$GATEKEEPER approving$and_submitting due to $plebicite total eligible votes\" $AUTO_SUBMIT_ON_QUORACY";
}
else {
        $review = " --code-review=0 --message=\"$GATEKEEPER ignoring $plebicite total eligible votes\"";
        # print LOG "$V{commit}: $review\n";

        exit 0;
}

$response = response($review);

print LOG "RUNNING: $response\n";
$output = qx( $response 2>&1   );
if ($output =~ /\S/) {
        print LOG "$V{commit}: output from commenting: $output";
        $response = response(" --message=\"During \Q$review\E: \Q$output\E\"");
        print LOG "WARNING: $response\n";
        $output = qx( $response 2>&1   );
        print LOG "ERROR: $output\n";
}

exit 0;
于 2012-03-16T13:00:18.643 に答える
1

Gerrit では、いつ変更を送信できるかを定義するプロローグの「送信ルール」を設定できます。

ドキュメントには、作成者が自分の変更を承認できないようにする例など、いくつかの例が含まれています。

于 2013-01-19T01:17:07.033 に答える
0

Gerrit インストール用にこのプロローグ フィルターを作成しました。システム内のすべてのプロジェクトに適用したかったので、親プロジェクトで submit_filter として実行しました。

%filter to require all projects to have a code-reviewer other than the owner
submit_filter(In, Out) :-
    %unpack the submit rule into a list of code reviews
    In =.. [submit | Ls],
    %add the non-owner code review requiremet
    reject_self_review(Ls, R),
    %pack the list back up and return it (kinda)
    Out =.. [submit | R].

reject_self_review(S1, S2) :-
    %set O to be the change owner
    gerrit:change_owner(O),
    %find a +2 code review, if it exists, and set R to be the reviewer
    gerrit:commit_label(label('Code-Review', 2), R), 
    %if there is a +2 review from someone other than the owner, then the filter has no work to do, assign S2 to S1
    R \= O, !,
    %the cut (!) predicate prevents further rules from being consulted
    S2 = S1.
reject_self_review(S1, S2) :-
    %set O to be the change owner
    gerrit:change_owner(O),
    % find a +2 code review, if it exists, and set R to be the reviewer - comment sign was missing
    gerrit:commit_label(label('Code-Review', 2), R), 
    R = O, !,
    %if there isn't a +2 from someone else (above rule), and there is a +2 from the owner, reject with a self-reviewed label
    S2 = [label('Self-Reviewed', reject(O))|S1].
%if the above two rules didn't make it to the ! predicate, there aren't any +2s so let the default rules through unfiltered
reject_self_review(S1, S1).

クックブックのルール #8に対するこのルールの利点 (IMO) は次のとおりです。

  • ラベルは、すべての変更にラベルをSelf-Reviewed追加するのではなく、変更がブロックされている場合にのみ表示されますNon-Author-Code-Review
  • reject(O)ルールを使用すると、Self-Reviewedラベルは文字通り赤い旗になります
  • submit_filter代わりにsubmit_rule、このルールは親プロジェクトにインストールされ、すべてのサブプロジェクトに適用されます

注:このルールはOwner、クックブックの例を と比較しながら、 が変更を自己レビューするのを防ぐために作成されていAuthorます。gerrit:change_owner(O)ワークフローによっては、2 つの述語をgerrit:commit_author(O)またはに置き換えたい場合があります。gerrit:commit_committer(O)

于 2016-06-16T17:00:50.260 に答える
0

アクセスタブのGUIから行うことができます。/refs/heads/ セクションに移動 -> Label Code-Review セクションにグループ 'change owner' を追加 -> -1..+1 を選択

これにより、所有者が変更され、-1 から +1 を与える特権が与えられます。

于 2017-01-11T05:18:21.193 に答える