Skip to content

Commit

Permalink
Item11267: Add support for Item specific branches.
Browse files Browse the repository at this point in the history
Checkins to any branch named ItemNNNNNN (2-6 digits)  with any suffix will now be
processed when the web push occurs.

 - Full branch name is recorded in CheckinsOnBranches
 - Git hash refs recorded into ItemBranchCheckins

Note that the task update is not restricted to the task prefixed in
the branch-name.  All tasks in the commit message will be updated with
the branch specific checkin information.

I'm not sure what will happen once the branch is merged into master.
The commit hashes might become dead links.
  • Loading branch information
gac410 committed Sep 8, 2014
1 parent 2b94114 commit c3a057c
Show file tree
Hide file tree
Showing 2 changed files with 139 additions and 13 deletions.
32 changes: 20 additions & 12 deletions lib/Foswiki/Plugins/FoswikiOrgPlugin/Core.pm
Expand Up @@ -329,6 +329,26 @@ sub _updateTask {
$Foswiki::cfg{Plugins}{FoswikiOrgPlugin}{TasksWeb}, $taskItem );

my $changed;

my $formField = $meta->get( 'FIELD', 'CheckinsOnBranches' );
my $value;
$value = $formField->{'value'} if ( defined $formField );
unless ( $value =~ m/\b\Q$branch\E\b/ ) {
$changed = 1;
Foswiki::Plugins::FoswikiOrgPlugin::writeDebug(
"Added $branch to CheckinsOnBranches for $taskItem");
$value .= ' ' if $value;
$value .= $branch;
$meta->putKeyed( 'FIELD',
{ name => 'CheckinsOnBranches', value => $value } );
}

# Adjust for Item specific branches. The complete branch name was recorded in CheckinsOnBranches
# but the individual commits are combined into 'ItemBranchCheckins'
if ( $branch =~ m/^(Item[0-9]{4,6})/ ) {
$branch = 'ItemBranch';
}

foreach my $field ( 'Checkins', "${branch}Checkins" ) {
my $formField = $meta->get( 'FIELD', $field );
my $value;
Expand All @@ -342,18 +362,6 @@ sub _updateTask {
$meta->putKeyed( 'FIELD', { name => $field, value => $value } );
}
}
my $formField = $meta->get( 'FIELD', 'CheckinsOnBranches' );
my $value;
$value = $formField->{'value'} if ( defined $formField );
unless ( $value =~ m/\b\Q$branch\E\b/ ) {
$changed = 1;
Foswiki::Plugins::FoswikiOrgPlugin::writeDebug(
"Added $branch to CheckinsOnBranches for $taskItem");
$value .= ' ' if $value;
$value .= $branch;
$meta->putKeyed( 'FIELD',
{ name => 'CheckinsOnBranches', value => $value } );
}

if ($changed) {
my $cUID =
Expand Down
120 changes: 119 additions & 1 deletion test/unit/FoswikiOrgPlugin/FoswikiOrgPluginTests.pm
Expand Up @@ -12,6 +12,11 @@ my $payload =

#' # vim formatting messes up due to the long line. This restores it.

my $ItemBranchPayload =
'{ "ref": "refs/heads/Item13010", "after": "ed689e67f1299e8f4dac37e6ddd3f0eb398ae858", "before": "0000000000000000000000000000000000000000", "created": true, "deleted": false, "forced": true, "compare": "https://github.com/foswiki/FastCGIEngineContrib/commit/ed689e67f129", "commits": [ { "id": "ed689e67f1299e8f4dac37e6ddd3f0eb398ae858", "distinct": true, "message": "Item13010:Item12909: fixes fcgi instabiltiy\n\n- when run under ProcManager\n- add a spec file as well\n- removed taint mode from respawned workers", "timestamp": "2014-08-29T14:49:50+02:00", "url": "https://github.com/foswiki/FastCGIEngineContrib/commit/ed689e67f1299e8f4dac37e6ddd3f0eb398ae858", "author": { "name": "TheAuthor", "email": "theauthor@foswiki.com", "username": "TheAuthor" }, "committer": { "name": "TheAuthor", "email": "theauthor@foswiki.com", "username": "TheAuthor" }, "added": [ ".gitignore", "lib/FCGI/ProcManager/Constrained.pm", "lib/Foswiki/Contrib/FastCGIEngineContrib/Config.spec" ], "removed": [ ], "modified": [ "bin/foswiki.fcgi", "data/System/FastCGIEngineContrib.txt", "lib/Foswiki/Contrib/FastCGIEngineContrib/MANIFEST", "lib/Foswiki/Engine/FastCGI.pm", "lib/Foswiki/Engine/FastCGI/ProcManager.pm", "tools/foswiki.defaults", "tools/foswiki.init-script" ] } ], "head_commit": { "id": "ed689e67f1299e8f4dac37e6ddd3f0eb398ae858", "distinct": true, "message": "Item13010:Item12909: fixes fcgi instabiltiy\n\n- when run under ProcManager\n- add a spec file as well\n- removed taint mode from respawned workers", "timestamp": "2014-08-29T14:49:50+02:00", "url": "https://github.com/foswiki/FastCGIEngineContrib/commit/ed689e67f1299e8f4dac37e6ddd3f0eb398ae858", "author": { "name": "TheAuthor", "email": "theauthor@foswiki.com", "username": "TheAuthor" }, "committer": { "name": "TheAuthor", "email": "theauthor@foswiki.com", "username": "TheAuthor" }, "added": [ ".gitignore", "lib/FCGI/ProcManager/Constrained.pm", "lib/Foswiki/Contrib/FastCGIEngineContrib/Config.spec" ], "removed": [ ], "modified": [ "bin/foswiki.fcgi", "data/System/FastCGIEngineContrib.txt", "lib/Foswiki/Contrib/FastCGIEngineContrib/MANIFEST", "lib/Foswiki/Engine/FastCGI.pm", "lib/Foswiki/Engine/FastCGI/ProcManager.pm", "tools/foswiki.defaults", "tools/foswiki.init-script" ] }, "repository": { "id": 1229874, "name": "FastCGIEngineContrib", "full_name": "foswiki/FastCGIEngineContrib", "owner": { "name": "foswiki", "email": "foswiki-discuss@lists.sourceforge.net" }, "private": false, "html_url": "https://github.com/foswiki/FastCGIEngineContrib", "description": "Foswiki\'s FastCGIEngineContrib", "fork": false, "url": "https://github.com/foswiki/FastCGIEngineContrib", "forks_url": "https://api.github.com/repos/foswiki/FastCGIEngineContrib/forks", "keys_url": "https://api.github.com/repos/foswiki/FastCGIEngineContrib/keys{/key_id}", "collaborators_url": "https://api.github.com/repos/foswiki/FastCGIEngineContrib/collaborators{/collaborator}", "teams_url": "https://api.github.com/repos/foswiki/FastCGIEngineContrib/teams", "hooks_url": "https://api.github.com/repos/foswiki/FastCGIEngineContrib/hooks", "issue_events_url": "https://api.github.com/repos/foswiki/FastCGIEngineContrib/issues/events{/number}", "events_url": "https://api.github.com/repos/foswiki/FastCGIEngineContrib/events", "assignees_url": "https://api.github.com/repos/foswiki/FastCGIEngineContrib/assignees{/user}", "branches_url": "https://api.github.com/repos/foswiki/FastCGIEngineContrib/branches{/branch}", "tags_url": "https://api.github.com/repos/foswiki/FastCGIEngineContrib/tags", "blobs_url": "https://api.github.com/repos/foswiki/FastCGIEngineContrib/git/blobs{/sha}", "git_tags_url": "https://api.github.com/repos/foswiki/FastCGIEngineContrib/git/tags{/sha}", "git_refs_url": "https://api.github.com/repos/foswiki/FastCGIEngineContrib/git/refs{/sha}", "trees_url": "https://api.github.com/repos/foswiki/FastCGIEngineContrib/git/trees{/sha}", "statuses_url": "https://api.github.com/repos/foswiki/FastCGIEngineContrib/statuses/{sha}", "languages_url": "https://api.github.com/repos/foswiki/FastCGIEngineContrib/languages", "stargazers_url": "https://api.github.com/repos/foswiki/FastCGIEngineContrib/stargazers", "contributors_url": "https://api.github.com/repos/foswiki/FastCGIEngineContrib/contributors", "subscribers_url": "https://api.github.com/repos/foswiki/FastCGIEngineContrib/subscribers", "subscription_url": "https://api.github.com/repos/foswiki/FastCGIEngineContrib/subscription", "commits_url": "https://api.github.com/repos/foswiki/FastCGIEngineContrib/commits{/sha}", "git_commits_url": "https://api.github.com/repos/foswiki/FastCGIEngineContrib/git/commits{/sha}", "comments_url": "https://api.github.com/repos/foswiki/FastCGIEngineContrib/comments{/number}", "issue_comment_url": "https://api.github.com/repos/foswiki/FastCGIEngineContrib/issues/comments/{number}", "contents_url": "https://api.github.com/repos/foswiki/FastCGIEngineContrib/contents/{+path}", "compare_url": "https://api.github.com/repos/foswiki/FastCGIEngineContrib/compare/{base}...{head}", "merges_url": "https://api.github.com/repos/foswiki/FastCGIEngineContrib/merges", "archive_url": "https://api.github.com/repos/foswiki/FastCGIEngineContrib/{archive_format}{/ref}", "downloads_url": "https://api.github.com/repos/foswiki/FastCGIEngineContrib/downloads", "issues_url": "https://api.github.com/repos/foswiki/FastCGIEngineContrib/issues{/number}", "pulls_url": "https://api.github.com/repos/foswiki/FastCGIEngineContrib/pulls{/number}", "milestones_url": "https://api.github.com/repos/foswiki/FastCGIEngineContrib/milestones{/number}", "notifications_url": "https://api.github.com/repos/foswiki/FastCGIEngineContrib/notifications{?since,all,participating}", "labels_url": "https://api.github.com/repos/foswiki/FastCGIEngineContrib/labels{/name}", "releases_url": "https://api.github.com/repos/foswiki/FastCGIEngineContrib/releases{/id}", "created_at": 1294412229, "updated_at": "2014-08-09T03:50:32Z", "pushed_at": 1409316715, "git_url": "git://github.com/foswiki/FastCGIEngineContrib.git", "ssh_url": "git@github.com:foswiki/FastCGIEngineContrib.git", "clone_url": "https://github.com/foswiki/FastCGIEngineContrib.git", "svn_url": "https://github.com/foswiki/FastCGIEngineContrib", "homepage": "http://foswiki.org/Extensions/FastCGIEngineContrib", "size": 180, "stargazers_count": 1, "watchers_count": 1, "language": "Perl", "has_issues": false, "has_downloads": false, "has_wiki": false, "forks_count": 0, "mirror_url": null, "open_issues_count": 0, "forks": 0, "open_issues": 0, "watchers": 1, "default_branch": "master", "stargazers": 1, "master_branch": "master", "organization": "foswiki" }, "pusher": { "name": "TheAuthor", "email": "theauthor@foswiki.com" }, "ref_name": "Item13010", "distinct_commits": [ { "id": "ed689e67f1299e8f4dac37e6ddd3f0eb398ae858", "distinct": true, "message": "Item13010:Item12909: fixes fcgi instabiltiy\n\n- when run under ProcManager\n- add a spec file as well\n- removed taint mode from respawned workers", "timestamp": "2014-08-29T14:49:50+02:00", "url": "https://github.com/foswiki/FastCGIEngineContrib/commit/ed689e67f1299e8f4dac37e6ddd3f0eb398ae858", "author": { "name": "TheAuthor", "email": "theauthor@foswiki.com", "username": "TheAuthor" }, "committer": { "name": "TheAuthor", "email": "theauthor@foswiki.com", "username": "TheAuthor" }, "added": [ ".gitignore", "lib/FCGI/ProcManager/Constrained.pm", "lib/Foswiki/Contrib/FastCGIEngineContrib/Config.spec" ], "removed": [ ], "modified": [ "bin/foswiki.fcgi", "data/System/FastCGIEngineContrib.txt", "lib/Foswiki/Contrib/FastCGIEngineContrib/MANIFEST", "lib/Foswiki/Engine/FastCGI.pm", "lib/Foswiki/Engine/FastCGI/ProcManager.pm", "tools/foswiki.defaults", "tools/foswiki.init-script" ] } ] }';

#' # vim formatting messes up due to the long line. This restores it.

sub new {
my $self = shift()->SUPER::new(@_);
return $self;
Expand Down Expand Up @@ -84,6 +89,62 @@ TASK
$testTask );
$topicObject->save();

my $brTask1 = <<TASK1;
%META:TOPICINFO{author="TheAuthor" comment="reprev" date="1409319676" format="1.1" reprev="1" version="1"}%
%META:TOPICPARENT{name="FastCGIEngineContrib"}%
When using FastCGIEngineContrib in an nginx setup the Foswiki engine has to be set up using a separate process controlled by an init script of the operating system (in /etc/init.d/foswiki).
%META:FORM{name="Tasks.ItemTemplate"}%
%META:FIELD{name="Summary" attributes="M" title="Summary" value="fcgi unstable when run under <nop>ProcManager"}%
%META:FIELD{name="ReportedBy" attributes="M" title="ReportedBy" value="Main.TheAuthor"}%
%META:FIELD{name="Codebase" attributes="" title="[[Codebase]]" value=""}%
%META:FIELD{name="SVNRange" attributes="" title="SVN Range" value=""}%
%META:FIELD{name="AppliesTo" attributes="M" title="AppliesTo" value="Extension"}%
%META:FIELD{name="Component" attributes="" title="Component" value="FastCGIEngineContrib"}%
%META:FIELD{name="Priority" attributes="M" title="[[Priority]]" value="Urgent"}%
%META:FIELD{name="CurrentState" attributes="M" title="CurrentState" value="Being Worked On"}%
%META:FIELD{name="WaitingFor" attributes="" title="WaitingFor" value=""}%
%META:FIELD{name="Checkins" attributes="" title="Checkins" value=""}%
%META:FIELD{name="ReleasedIn" attributes="" title="ReleasedIn" value="n/a"}%
%META:FIELD{name="CheckinsOnBranches" attributes="" title="CheckinsOnBranches" value=""}%
%META:FIELD{name="trunkCheckins" attributes="" title="trunkCheckins" value=""}%
%META:FIELD{name="masterCheckins" attributes="" title="masterCheckins" value=""}%
%META:FIELD{name="Release01x01Checkins" attributes="" title="Release01x01Checkins" value=""}%
%META:PREFERENCE{name="VIEW_TEMPLATE" title="VIEW_TEMPLATE" type="Set" value="ItemView"}%
TASK1

$topicObject =
Foswiki::Meta->new( $this->{session}, $this->{test_web}, "Item13010",
$brTask1 );
$topicObject->save();

my $brTask2 = <<TASK2;
%META:TOPICINFO{author="AnotherAuthor" comment="reprev" date="1400808689" format="1.1" reprev="2" version="2"}%
%META:TOPICPARENT{name="FastCGIEngineContrib"}%
%META:FORM{name="Tasks.ItemTemplate"}%
%META:FIELD{name="Summary" attributes="M" title="Summary" value="FastCGIContrib does not have a Config.spec and hence its settings do not appear in /bin/configure."}%
%META:FIELD{name="ReportedBy" attributes="M" title="ReportedBy" value="Main.FredTarbox"}%
%META:FIELD{name="Codebase" attributes="" title="[[Codebase]]" value="trunk"}%
%META:FIELD{name="SVNRange" attributes="" title="SVN Range" value=""}%
%META:FIELD{name="AppliesTo" attributes="M" title="AppliesTo" value="Extension"}%
%META:FIELD{name="Component" attributes="" title="Component" value="FastCGIEngineContrib"}%
%META:FIELD{name="Priority" attributes="M" title="[[Priority]]" value="Normal"}%
%META:FIELD{name="CurrentState" attributes="M" title="CurrentState" value="Confirmed"}%
%META:FIELD{name="WaitingFor" attributes="" title="WaitingFor" value=""}%
%META:FIELD{name="Checkins" attributes="" title="Checkins" value=""}%
%META:FIELD{name="ReleasedIn" attributes="" title="ReleasedIn" value="n/a"}%
%META:FIELD{name="CheckinsOnBranches" attributes="" title="CheckinsOnBranches" value=""}%
%META:FIELD{name="trunkCheckins" attributes="" title="trunkCheckins" value=""}%
%META:FIELD{name="Release01x01Checkins" attributes="" title="Release01x01Checkins" value=""}%
%META:PREFERENCE{name="VIEW_TEMPLATE" title="VIEW_TEMPLATE" type="Set" value="ItemView"}%
TASK2

$topicObject =
Foswiki::Meta->new( $this->{session}, $this->{test_web}, "Item12909",
$brTask2 );
$topicObject->save();

$Foswiki::cfg{Register}{AllowLoginName} = 0;

$this->registerUser( 'theauthor', 'The', "Author",
Expand All @@ -106,7 +167,7 @@ sub loadExtraConfig {
'Foswiki::Plugins::FoswikiOrgPlugin';
$Foswiki::cfg{Plugins}{FoswikiOrgPlugin}{GithubSecret} = 'asdfasdf';
$Foswiki::cfg{Plugins}{FoswikiOrgPlugin}{TrackingBranches} =
qr/^(master|Release01x00|Release01x01|Release01x02)$/;
qr/^(master|Release01x00|Release01x01|Release01x02|Item[0-9]{3,7}.*)$/;
$Foswiki::cfg{Plugins}{FoswikiOrgPlugin}{Workarea} = '';
$Foswiki::cfg{Plugins}{FoswikiOrgPlugin}{TasksWeb} = $this->{test_web};
$Foswiki::cfg{Plugins}{FoswikiOrgPlugin}{SecurityGroup} = 'SecurityGroup';
Expand Down Expand Up @@ -146,6 +207,63 @@ sub test_processValidatedPayload {
$this->assert_equals( 'Release01x01 trunk master', $value );
}

sub test_processValidatedPayload_ItemBranch {
my $this = shift;

require Foswiki::Plugins::FoswikiOrgPlugin::Core;

Foswiki::Plugins::FoswikiOrgPlugin::Core::_processValidatedPayload(
$this->{session}, undef, undef, $ItemBranchPayload );

my $topicObject =
Foswiki::Meta->load( $this->{session}, $this->{test_web}, "Item13010" );

my $ti = $topicObject->get('TOPICINFO');
$this->assert_equals( 'TheAuthor', $ti->{author} );

my $formField = $topicObject->get( 'FIELD', 'masterCheckins' );
my $value = $formField->{'value'};
$this->assert_equals( '', $value );

$formField = $topicObject->get( 'FIELD', 'Checkins' );
$value = $formField->{'value'};
$this->assert_matches( qr/%GITREF{FastCGIEngineContrib:ed689e67f129}%/,
$value );

$formField = $topicObject->get( 'FIELD', 'CheckinsOnBranches' );
$value = $formField->{'value'};
$this->assert_equals( 'Item13010', $value );

$formField = $topicObject->get( 'FIELD', 'ItemBranchCheckins' );
$value = $formField->{'value'};
$this->assert_matches( qr/%GITREF{FastCGIEngineContrib:ed689e67f129}%/,
$value );

$topicObject =
Foswiki::Meta->load( $this->{session}, $this->{test_web}, "Item12909" );

$ti = $topicObject->get('TOPICINFO');
$this->assert_equals( 'TheAuthor', $ti->{author} );

$formField = $topicObject->get( 'FIELD', 'masterCheckins' );
$value = $formField->{'value'};
$this->assert( !defined $value );

$formField = $topicObject->get( 'FIELD', 'Checkins' );
$value = $formField->{'value'};
$this->assert_matches( qr/%GITREF{FastCGIEngineContrib:ed689e67f129}%/,
$value );

$formField = $topicObject->get( 'FIELD', 'CheckinsOnBranches' );
$value = $formField->{'value'};
$this->assert_equals( 'Item13010', $value );

$formField = $topicObject->get( 'FIELD', 'ItemBranchCheckins' );
$value = $formField->{'value'};
$this->assert_matches( qr/%GITREF{FastCGIEngineContrib:ed689e67f129}%/,
$value );
}

sub test_update_Task {
my $this = shift;

Expand Down

0 comments on commit c3a057c

Please sign in to comment.