App-GHGen

 view release on metacpan or  search on metacpan

lib/App/GHGen/Fixer.pm  view on Meta::CPAN

        group => '${{ github.workflow }}-${{ github.ref }}',
        'cancel-in-progress' => 'true',
    };
    return 1;
}

sub add_trigger_filters($workflow) {
	my $on = $workflow->{on} or return 0;
	my $modified = 0;

    # If 'on' is just 'push', expand it
    if (ref $on eq 'ARRAY' && grep { $_ eq 'push' } @$on) {
        $workflow->{on} = {
            push => {
                branches => ['main', 'master'],
            },
            pull_request => {
                branches => ['main', 'master'],
            },
        };
        $modified++;

t/extended_tests.t  view on Meta::CPAN

					{ run  => 'npm ci'             },
				],
			},
		},
	};
	my $result = App::GHGen::Fixer::add_caching($wf);
	is($result, 0, 'job already with cache skipped; count stays 0');
};

subtest 'Fixer::add_trigger_filters - HASH on with push as bare string (truthy scalar)' => sub {
	# Branch: ref $on->{push} eq '' with a truthy value → expand push to branches filter.
	# Note: the implementation tests $on->{push} && ref $on->{push} eq '', so the
	# scalar must be truthy (empty string is falsy and falls through).
	my $wf = { on => { push => '*' }, jobs => {} };
	my $n = App::GHGen::Fixer::add_trigger_filters($wf);
	is($n, 1, 'truthy scalar push value gets expanded');
	is(ref $wf->{on}{push}, 'HASH', 'push is now a HASH with filters');
	is_deeply($wf->{on}{push}{branches}, ['main', 'master'], 'default branches added');
};

subtest 'Fixer::add_trigger_filters - no on key returns 0' => sub {
	my $wf = { jobs => {} };
	my $n = App::GHGen::Fixer::add_trigger_filters($wf);
	is($n, 0, 'missing on key returns 0 modifications');
};



( run in 1.375 second using v1.01-cache-2.11-cpan-9169edd2b0e )