Skip to content

Commit

Permalink
add run download
Browse files Browse the repository at this point in the history
  • Loading branch information
Khetag Dzestelov committed Aug 16, 2024
1 parent e612e0c commit 6bd68ca
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 15 deletions.
22 changes: 18 additions & 4 deletions cmd/boban/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,18 @@ func main() {
Required: false,
Help: "Download runs source codes to directory",
})
shouldAppendComment := parser.Flag("e", "comments", &argparse.Options{
Required: false,
Help: "Should append comments to each run source file",
})
if err := parser.Parse(os.Args); err != nil {
logrus.WithError(err).Fatal("bad arguments")
}

if *shouldAppendComment == true && *inputSourcesDst == "" {
logrus.Fatal("-e (--comments) flag requires either --destination or -d flag")
}

cfg := config.NewConfig()
ejClient := ejudge.NewEjudge(&cfg.Ejudge)

Expand All @@ -58,15 +66,17 @@ func main() {
}

sourcesDst := ""
if len(*inputSourcesDst) > 0 {
if *inputSourcesDst != "" {
sourcesDst = makeContestDir(*inputSourcesDst, *cID)
}

for _, run := range runs {
fmt.Println(run) //nolint:forbidigo // Basic functionality.
if sourcesDst != "" {
filename := downloadSourceCode(ejClient, csid, run, sourcesDst)
appendCommentsToSourceCode(ejClient, csid, run, sourcesDst, filename)
if *shouldAppendComment == true {
appendCommentsToSourceCode(ejClient, csid, run, sourcesDst, filename)
}
}
}

Expand All @@ -75,6 +85,10 @@ func main() {
}
}

// Используется в review.sh
var CommentsSectionHeaderStart = "COMMENTS FOR CURRENT RUN"
var CommentsSectionPreviousHeaderStart = "COMMENTS FOR PREVIOUS RUN"

func appendCommentsToSourceCode(ejClient *ejudge.Ejudge, csid string, runId int, contestDestination string, runSourceCodeFilename string) {
currentComments, previousComments, _ := ejClient.GetAllComments(csid, runId)

Expand All @@ -84,8 +98,8 @@ func appendCommentsToSourceCode(ejClient *ejudge.Ejudge, csid string, runId int,
}
defer file.Close()

writeCommentSection(file, "COMMENTS FOR CURRENT RUN", currentComments)
writeCommentSection(file, "COMMENTS FOR PREVIOUS RUN", previousComments)
writeCommentSection(file, CommentsSectionHeaderStart, currentComments)
writeCommentSection(file, CommentsSectionPreviousHeaderStart, previousComments)
}

func writeCommentSection(file *os.File, header string, comments []ejudge.Comment) {
Expand Down
31 changes: 20 additions & 11 deletions scripts/review.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,39 @@ IYellow='\033[0;93m'
Cyan='\033[0;36m' # Cyan

if [ "$#" -lt 3 ]; then
echo "Usage: $0 <contestId> <filter> <count> [<0/1 disable PR filter>]"
echo "Usage: $0 <contestId> <filter> <count> [<showAll>]"
echo
echo " Run review for pending review filtered runs in contest."
echo
echo "Arguments:"
echo
echo " contestId (int) Contest id"
echo " filter (string) Filter expression to filter runs"
echo " count (int) Maximum count of runs to review"
echo " showAll (bool) Disable pending review runs filter"
exit 1
fi

contestId=$1
if [ "$4" == '1' ]; then
if [ "$4" == 'true' ]; then
filter=$2
echo -e "${Red}WARNING${NC} Pending review filter is disabled, don't OK the run uncontrollably!"
else
filter="($2)&&status==PR"
fi
count=$3

if [ -d "$contestId" ]; then
rm -r $contestId
fi

echo -e "${Cyan}INFO${NC} Filtering runs from contest [$contestId] with filter [$filter] and limit [$count]"
echo -e "${Cyan}INFO${NC} Reviewing ${IYellow}[$(boban -i "$contestId" -f "$filter" -c "$count" -d . | wc -l | xargs)]${NC} filtered runs"

cleanup() {
rm -r "$contestId"
if [ -d "$contestId" ]; then
rm -r $contestId
fi
}

cleanup

echo -e "${Cyan}INFO${NC} Filtering runs from contest [$contestId] with filter [$filter] and limit [$count]"
echo -e "${Cyan}INFO${NC} Reviewing ${IYellow}[$(boban -i "$contestId" -f "$filter" -c "$count" -e -d . | wc -l | xargs)]${NC} filtered runs"

for file in "$contestId"/*; do
if [ -f "$file" ]; then
filename=$(basename "$file")
Expand All @@ -45,7 +54,7 @@ for file in "$contestId"/*; do
cp "$file" "$current"
echo -e "${Cyan}INFO${NC} Review $file => $current"

runLinesCount=$(cat "$current" | awk '/=============== COMMENTS/{print NR-2; found=1; exit} END{if(!found) print NR}') # количестов строк кода в посылке до секции комментов
runLinesCount=$(cat "$current" | awk '/COMMENTS FOR CURRENT RUN/{print NR-2; found=1; exit} END{if(!found) print NR}') # количестов строк кода в посылке до секции комментов

while [ 1 ]; do
read -r -p "$(echo -e "${Green}INTERACT${NC}") Type the resolution ($(echo -e "${Green}OK(щл)${NC}/${Red}RJ(ко)${NC}/skip/rejudge")): " verdict
Expand Down

0 comments on commit 6bd68ca

Please sign in to comment.