<commit_before>#!/usr/bin/env perl

=head DESCRIPTION

Release Engineering scripts for [myProject].
(copied from https://github.com/mackerelio/mackerel-agent/blob/master/_tools/releng)

=head SYNOPSIS

    % myproject-release
        --help
        --task=<task>            # 'create-pullrequest' or 'github-release'
        --next-version=<version> # specify next version. if not specified, a
                                 # value derived from the branch name is used.
        --package-name=<name>    # target package name. if not specified,
                                 # the repository name is used.
        --verbose
        --dry-run

=head DEPENDENCY

`git` command and `hub` (or `gh`) command and `github-release` command are required.

=cut

use 5.014;
use strict;
use warnings;
use utf8;
use Carp;

use IPC::Cmd qw/run/;
use JSON::PP;
use ExtUtils::MakeMaker qw/prompt/;
use Time::Piece;
use POSIX qw(setlocale LC_TIME);
use version;
use Getopt::Long;
use File::Basename;

chomp(my $REPO_NAME = `git rev-parse --show-toplevel`);
$REPO_NAME =~ s|^.+/([^/]+/[^/]+)$|$1|;
$REPO_NAME =~ m!/([^/]+)$!;
my $REPO = $1;
$REPO_NAME =~ m!^([^/]+)!;
my $REPO_USER = $1;
my $dry_run;
my $verbose;
my $next_version;
my $package_name = $REPO;

sub DEBUG() { $ENV{RELEASE_DEBUG} || $verbose }

sub command {
    say('+ '. join ' ', @_) if DEBUG;
    my @args = (@_ , (">& /dev/null"));
    !system("@args") or croak $!;
}
sub command_with_exit_code {
    say('+ '. join ' ', @_) if DEBUG;
    my @args = (@_ , (">& /dev/null"));
    system("@args");
}
sub _git {
    if($dry_run){
        return
    }
    state $com = do {
        chomp(my $c = `which git`);
        die "git command is required\n" unless $c;
        $c;
    };
}
sub git {
    if($dry_run){
        return
    }
    unshift  @_, _git; goto \&command
}

sub git_with_exit_code {
    if($dry_run){
        return
    }
    unshift  @_, _git; goto \&command_with_exit_code
}


sub _hub {
    if($dry_run){
        return<commit_msg>Fix deploy script<commit_after>#!/usr/bin/env perl

=head DESCRIPTION

Release Engineering scripts for [myProject].
(copied from https://github.com/mackerelio/mackerel-agent/blob/master/_tools/releng)

=head SYNOPSIS

    % myproject-release
        --help
        --task=<task>            # 'create-pullrequest' or 'github-release'
        --next-version=<version> # specify next version. if not specified, a
                                 # value derived from the branch name is used.
        --package-name=<name>    # target package name. if not specified,
                                 # the repository name is used.
        --verbose
        --dry-run

=head DEPENDENCY

`git` command and `hub` (or `gh`) command and `github-release` command are required.

=cut

use 5.014;
use strict;
use warnings;
use utf8;
use Carp;

use IPC::Cmd qw/run/;
use JSON::PP;
use ExtUtils::MakeMaker qw/prompt/;
use Time::Piece;
use POSIX qw(setlocale LC_TIME);
use version;
use Getopt::Long;
use File::Basename;

chomp(my $REPO_NAME = `git rev-parse --show-toplevel`);
$REPO_NAME =~ s|^.+/([^/]+/[^/]+)$|$1|;
$REPO_NAME =~ m!/([^/]+)$!;
my $REPO = $1;
$REPO_NAME =~ m!^([^/]+)!;
my $REPO_USER = $1;
my $dry_run;
my $verbose;
my $next_version;
my $package_name = $REPO;

sub DEBUG() { $ENV{RELEASE_DEBUG} || $verbose }

sub command {
    say('+ '. join ' ', @_) if DEBUG;
    my @args = (@_ , ("> /dev/null","2>&1"));
    !system("@args") or croak $!;
}
sub command_with_exit_code {
    say('+ '. join ' ', @_) if DEBUG;
    my @args = (@_ , ("> /dev/null","2>&1"));
    system("@args");
}
sub _git {
    if($dry_run){
        return
    }
    state $com = do {
        chomp(my $c = `which git`);
        die "git command is required\n" unless $c;
        $c;
    };
}
sub git {
    if($dry_run){
        return
    }
    unshift  @_, _git; goto \&command
}

sub git_with_exit_code {
    if($dry_run){
        return
    }
    unshift  @_, _git; goto \&command_with_exit_code
}


sub _hub {
    if($dry_run){
        return
{'fraction_non_alphanumeric': 0.1688247011952191, 'fraction_numerical': 0.0049800796812749, 'mean_word_length': 2.4839549002601906, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 15, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5496268', 'n_tokens_mistral': 1507, 'n_tokens_neox': 1462, 'n_words': 373}