Skip to content
This repository has been archived by the owner on Apr 13, 2021. It is now read-only.

Initial Staging Process for KSP-CKAN/CKAN#1679 #55

Merged
merged 15 commits into from
Aug 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ perl:
# - "5.22"
- "5.20"
- "5.18"
- "5.16"
- "5.14"
- "5.12"
- "5.10"
addons:
apt:
sources:
- git-core
packages:
- git
- aspell
before_install:
# Prevent "Please tell me who you are" errors for certain DZIL configs
- git config --global user.name "TravisCI"
Expand All @@ -22,6 +25,7 @@ install:
- cpanm --quiet --notest Devel::Cover::Report::Coveralls
- cpanm --quiet --notest Dist::Zilla::App::Command::cover
script:
- git --version
- dzil test
after_success:
- dzil cover -outputdir cover_db -report coveralls
3 changes: 3 additions & 0 deletions dist.ini
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ stopwords = ckan
stopwords = iaS
stopwords = sha
stopwords = mimetype
stopwords = kref
stopwords = vref
stopwords = untracked

[AutoPrereqs]

Expand Down
121 changes: 121 additions & 0 deletions lib/App/KSP_CKAN/Metadata/NetKAN.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
package App::KSP_CKAN::Metadata::NetKAN;

use v5.010;
use strict;
use warnings;
use autodie;
use Method::Signatures 20140224;
use Config::JSON; # Saves us from file handling
use List::MoreUtils 'any';
use Carp qw( croak );
use Digest::SHA 'sha1_hex';
use URI::Escape 'uri_unescape';
use Scalar::Util 'reftype';
use Moo;
use namespace::clean;

# ABSTRACT: Metadata Wrapper for CKAN files

# VERSION: Generated by DZP::OurPkg:Version

=head1 SYNOPSIS

use App::KSP_CKAN::Metadata::Ckan;

my $ckan = App::KSP_CKAN::Metadata::Ckan->new(
file => "/path/to/file.ckan",
);

=head1 DESCRIPTION

Provides a ckan metadata object for KSP-CKAN. Has the following
attributes available.

=over

=item identifier

Returns the identifier for the loaded NetKAN.

=item name

Returns the name for the loaded NetKAN.

=item kref

Returns the $kref or undef for the loaded NetKAN.

=item vref

Returns the $vref or undef for the loaded NetKAN.

=item staging

Returns false if not in metadata, else returns the value in the
metadata.

=item license

Returns the license for the loaded NetKAN.

=back

=cut

has 'file' => ( is => 'ro', required => 1 ); # TODO: we should do some validation here.
has '_raw' => ( is => 'ro', lazy => 1, builder => 1 );
has 'identifier' => ( is => 'ro', lazy => 1, builder => 1 );
has 'kref' => ( is => 'ro', lazy => 1, builder => 1 );
has 'vref' => ( is => 'ro', lazy => 1, builder => 1 );
has 'name' => ( is => 'ro', lazy => 1, builder => 1 );
has 'staging' => ( is => 'ro', lazy => 1, builder => 1 );
has 'license' => ( is => 'ro', lazy => 1, builder => 1 );

# TODO: We're already using file slurper + JSON elsewhere. We should
# pick one method for consistency.
# TODO: This could also barf out on an invalid file, we'll need to
# Handle that somewhere.
method _build__raw {
return Config::JSON->new($self->file);
}

method _build_identifier {
return $self->_raw->{config}{identifier};
}

method _build_kref {
return $self->_raw->{config}{'$kref'};
}

method _build_vref {
return $self->_raw->{config}{'$vref'} ? $self->_raw->{config}{'$vref'} : undef ;
}

method _build_name {
return $self->_raw->{config}{name};
}

method _build_license {
return $self->_raw->{config}{license} ? $self->_raw->{config}{license} : "unknown";
}

method _build_staging {
return $self->_raw->{config}{'x-netkan-staging'} ? $self->_raw->{config}{'x-netkan-staging'} : 0 ;
}

=method licenses

$ckan->licenses();

Returns the license field as an array. Because unless there is
multiple values it won't be.

=cut

# Sometimes we always want an array.
method licenses {
my @licenses = reftype \$self->license ne "SCALAR" ? @{$self->license} : $self->license;
return \@licenses;
}

1;
10 changes: 10 additions & 0 deletions lib/App/KSP_CKAN/Tools/Config.pm
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ has 'netkan_exe' => ( is => 'ro', lazy => 1, builder => 1 );
has 'ckan_validate' => ( is => 'ro', lazy => 1, builder => 1 );
has 'ckan_schema' => ( is => 'ro', lazy => 1, builder => 1 );
has 'GH_token' => ( is => 'ro', lazy => 1, builder => 1 );
has 'GH_user' => ( is => 'ro', lazy => 1, builder => 1 );
has 'GH_repo' => ( is => 'ro', lazy => 1, builder => 1 );
has 'IA_access' => ( is => 'ro', lazy => 1, builder => 1 );
has 'IA_secret' => ( is => 'ro', lazy => 1, builder => 1 );
has 'IA_collection' => ( is => 'ro', lazy => 1, builder => 1 );
Expand Down Expand Up @@ -90,6 +92,14 @@ method _build_IA_collection {
return $self->_config->{_}{'IA_collection'} ? $self->_config->{_}{'IA_collection'} : "test_collection";
}

method _build_GH_repo {
return $self->_config->{_}{'GH_repo'} ? $self->_config->{_}{'GH_repo'} : "CKAN-meta";
}

method _build_GH_user {
return $self->_config->{_}{'GH_user'} ? $self->_config->{_}{'GH_user'} : "KSP-CKAN";
}

method _build_GH_token {
if ( ! $self->_config->{_}{'GH_token'} ) {
return 0;
Expand Down
Loading