2011-06-06 14 views
8

में सहकर्मी समीक्षक सूची से लेखक को छोड़कर मैं अपनी कंपनी के लिए गेरिट में एक्सेस नियंत्रण स्थापित कर रहा हूं और हमारी वर्तमान आंतरिक प्रक्रिया में सहकर्मी समीक्षकों और कोडर्स के बीच पार हो गया है (वे लोगों का एक ही समूह हैं) । हम कोड की समीक्षा करने के लिए केवल 1 समीक्षक की आवश्यकता होती है और यदि यह अच्छा लगती है तो इसे जमा करें।गेरिट

डिफ़ॉल्ट सेटअप के साथ +2: Looks good to me, approved विकल्प वाला कोई भी उपयोगकर्ता अपने कोड की समीक्षा कर सकता है।

क्या लेखक को अपने कोड की समीक्षा करने से रोकने का कोई तरीका है, लेकिन फिर भी उन्हें अन्य कोड की पूरी समीक्षा करने की अनुमति है? मैं एक्सेस कंट्रोल ग्रुप सेटअप या अनुमति सेटअप में किसी भी प्रकार का बहिष्कृत लेखक नहीं ढूंढ पा रहा हूं।

+1

क्या आप वाकई इसे मजबूर करना चाहते हैं? प्रोग्रामर बुद्धिमान लोग हैं, बस इसे एक नियम बनाओ। कुछ कोने मामलों में आपके स्वयं के कोड की समीक्षा उपयोगी हो सकती है (यानी कोड पहले से ही समीक्षा की गई थी लेकिन आपने प्रतिबद्ध संदेश में गलत वर्तनी तय की, इस मामले में एक और समीक्षा समय खो जाएगी)। –

+3

@ टोमाज़विसाकी मैं बस इतना कह सकता हूं कि जब प्रोग्राम निर्धारित प्रक्रिया की बात आती है तो प्रोग्रामर बुद्धिमान से दूर होते हैं। बेवकूफ डेवलपर्स की वजह से मैं कुछ समय के लिए गेरिट में इस सुविधा की तलाश कर रहा हूं। विशिष्ट उदाहरण जो आप अपने काम की समीक्षा करना चाहते हैं, पूरे सिस्टम को गलत उपयोग के लिए खोलता है। क्या एक और सहकर्मी समीक्षक से एक साधारण परिवर्तन की समीक्षा करने के लिए यह बहुत कुछ है! बस जोड़ने के लिए मैं एक डेवलपर हूँ। – Tnem

+0

यह उत्तर देखें: [ब्लॉक स्टेटमेंट का उपयोग करें] (https://stackoverflow.com/questions/11560812/exclude-author-from-gerrit-review/47887713#47887713) – very

उत्तर

2

यह मेरे लिए काम कर रहा है, लेकिन यह एक त्वरित हैक है:

  • + +1 का विन्यास संख्या मैनुअल प्रस्तुत करने के लिए एक 2 के रूप में गिनती करने के लिए
  • वैकल्पिक रूप से स्वचालित रूप से पर्याप्त +1 वोट
  • साथ प्रस्तुत की अनुमति देता है
  • वैकल्पिक रूप से मिलान के प्रयोजनों के लिए मुकाबला +1 वोट के रूप में -1 वोट मायने रखता है
  • वैकल्पिक रूप से ध्यान नहीं देता है अपलोड करने वाले की अपनी +1 (आप लेखक है, जो मैं नहीं किया है के खिलाफ एक चेक पसंद कर सकते हैं)

मैंने अपने पहले के जवाब को tweaked किया है, इसलिए यह नहीं लगता कि आप एक MySQL सर्वर का उपयोग कर रहे हैं।

आप कहीं भी लॉगफाइल को स्थानांतरित करना चाहते हैं, यह किसी भी सामान्य लॉग रोटेशन के अधीन होगा - शायद ../logs/comment-added.log में।

मैंने कॉन्फ़िगर करने योग्य बिट्स को सामने खींचने की कोशिश की है। इस फ़ाइल को कॉल करें-हुक और इसे $ gerrit_root/hooks में डालें, इसे 755 या इसी तरह के chmod करें। व्यवस्थापक समूह में रोबोट उपयोगकर्ता सेट करें ताकि हुक एसक्यूएल इंटरफेस का उपयोग कर सके (और पर्याप्त + 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; 
0

Gerrit आप prolog की स्थापना की है कि परिभाषित जब एक परिवर्तन submittable है "नियम सबमिट करें" की अनुमति देता है।

documentation में कई उदाहरण शामिल हैं, जिनमें लेखक को अपना स्वयं का परिवर्तन मंजूर करने से रोकता है।

+0

जैसा कि [दस्तावेज़ीकरण] में उल्लेख किया गया है (https://gerrit-review.googlesource.com/Documentation/prolog-cookbook.html#RulesFile) 'rule.pl' फ़ाइल को 'refs/meta/config' में रखा जाना चाहिए परियोजना की शाखा। –

3

The Gerrit Cookbook Example 8 लेखक को अपने स्वयं के परिवर्तन की समीक्षा करने के लिए सख्ती से नहीं रोकता है, लेकिन सबमिट करने में सक्षम होने से पहले किसी और को +2 की आवश्यकता होगी।

0

मैंने अभी हमारे गेरिट इंस्टॉलेशन के लिए यह प्रोलॉग फ़िल्टर लिखा है। मैंने इसे मूल परियोजना में 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 
    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). 

rule #8 from the cookbook से अधिक इस नियम के लाभ (IMO) कर रहे हैं:

  • Self-Reviewed लेबल केवल दिखाया गया है जब परिवर्तन अवरुद्ध किया जा रहा है, बल्कि हर परिवर्तन करने के लिए एक Non-Author-Code-Review लेबल जोड़ने से
  • reject(O) का उपयोग कर नियम से Self-Reviewed लेबल का कारण बनता है सचमुच एक लाल झंडा
  • होने के लिए एक के रूप में 0,123,966 एक submit_rule के बजाय, इस नियम एक माता पिता परियोजना में स्थापित किया है और सभी उप-परियोजनाओं

कृपया ध्यान दें पर लागू होता है: यह नियम स्वयं की समीक्षा एक परिवर्तन से Owner को रोकने के लिए लेखक है, उदाहरण के जबकि कुकबुक से Author के खिलाफ तुलना करता है। आपके वर्कफ़्लो के आधार पर, आप gerrit:change_owner(O) को gerrit:commit_author(O) या gerrit:commit_committer(O)

0

से भविष्यवाणी करना चाहते हैं, आप इसे एक्सेस टैब में जीयूआई से कर सकते हैं। लेबल कोड-समीक्षा अनुभाग में समूह 'परिवर्तन स्वामी' जोड़ें -> -1 चुनें .. + 1

इससे परिवर्तन मालिक को -1 देने के लिए विशेषाधिकार मिलेगा +1

संबंधित मुद्दे