Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F679838
HarbormasterLeaseWorkingCopyBuildStepImplementation.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
5 KB
Referenced Files
None
Subscribers
None
HarbormasterLeaseWorkingCopyBuildStepImplementation.php
View Options
<?php
final
class
HarbormasterLeaseWorkingCopyBuildStepImplementation
extends
HarbormasterBuildStepImplementation
{
public
function
getName
()
{
return
pht
(
'Lease Working Copy'
);
}
public
function
getGenericDescription
()
{
return
pht
(
'Build a working copy in Drydock.'
);
}
public
function
getBuildStepGroupKey
()
{
return
HarbormasterPrototypeBuildStepGroup
::
GROUPKEY
;
}
public
function
execute
(
HarbormasterBuild
$build
,
HarbormasterBuildTarget
$build_target
)
{
$viewer
=
PhabricatorUser
::
getOmnipotentUser
();
$settings
=
$this
->
getSettings
();
// TODO: We should probably have a separate temporary storage area for
// execution stuff that doesn't step on configuration state?
$lease_phid
=
$build_target
->
getDetail
(
'exec.leasePHID'
);
if
(
$lease_phid
)
{
$lease
=
id
(
new
DrydockLeaseQuery
())
->
setViewer
(
$viewer
)
->
withPHIDs
(
array
(
$lease_phid
))
->
executeOne
();
if
(!
$lease
)
{
throw
new
PhabricatorWorkerPermanentFailureException
(
pht
(
'Lease "%s" could not be loaded.'
,
$lease_phid
));
}
}
else
{
$working_copy_type
=
id
(
new
DrydockWorkingCopyBlueprintImplementation
())
->
getType
();
$lease
=
id
(
new
DrydockLease
())
->
setResourceType
(
$working_copy_type
)
->
setOwnerPHID
(
$build_target
->
getPHID
());
$map
=
$this
->
buildRepositoryMap
(
$build_target
);
$lease
->
setAttribute
(
'repositories.map'
,
$map
);
$task_id
=
$this
->
getCurrentWorkerTaskID
();
if
(
$task_id
)
{
$lease
->
setAwakenTaskIDs
(
array
(
$task_id
));
}
$lease
->
queueForActivation
();
$build_target
->
setDetail
(
'exec.leasePHID'
,
$lease
->
getPHID
())
->
save
();
}
if
(
$lease
->
isActivating
())
{
// TODO: Smart backoff?
throw
new
PhabricatorWorkerYieldException
(
15
);
}
if
(!
$lease
->
isActive
())
{
// TODO: We could just forget about this lease and retry?
throw
new
PhabricatorWorkerPermanentFailureException
(
pht
(
'Lease "%s" never activated.'
,
$lease
->
getPHID
()));
}
$artifact
=
$build_target
->
createArtifact
(
$viewer
,
$settings
[
'name'
],
HarbormasterWorkingCopyArtifact
::
ARTIFACTCONST
,
array
(
'drydockLeasePHID'
=>
$lease
->
getPHID
(),
));
}
public
function
getArtifactOutputs
()
{
return
array
(
array
(
'name'
=>
pht
(
'Working Copy'
),
'key'
=>
$this
->
getSetting
(
'name'
),
'type'
=>
HarbormasterWorkingCopyArtifact
::
ARTIFACTCONST
,
),
);
}
public
function
getFieldSpecifications
()
{
return
array
(
'name'
=>
array
(
'name'
=>
pht
(
'Artifact Name'
),
'type'
=>
'text'
,
'required'
=>
true
,
),
'repositoryPHIDs'
=>
array
(
'name'
=>
pht
(
'Also Clone'
),
'type'
=>
'datasource'
,
'datasource.class'
=>
'DiffusionRepositoryDatasource'
,
),
);
}
private
function
buildRepositoryMap
(
HarbormasterBuildTarget
$build_target
)
{
$viewer
=
PhabricatorUser
::
getOmnipotentUser
();
$variables
=
$build_target
->
getVariables
();
$repository_phid
=
idx
(
$variables
,
'repository.phid'
);
if
(!
$repository_phid
)
{
throw
new
Exception
(
pht
(
'Unable to determine how to clone the repository for this '
.
'buildable: it is not associated with a tracked repository.'
));
}
$also_phids
=
$build_target
->
getFieldValue
(
'repositoryPHIDs'
);
$all_phids
=
$also_phids
;
$all_phids
[]
=
$repository_phid
;
$repositories
=
id
(
new
PhabricatorRepositoryQuery
())
->
setViewer
(
$viewer
)
->
withPHIDs
(
$all_phids
)
->
execute
();
$repositories
=
mpull
(
$repositories
,
null
,
'getPHID'
);
foreach
(
$all_phids
as
$phid
)
{
if
(
empty
(
$repositories
[
$phid
]))
{
throw
new
PhabricatorWorkerPermanentFailureException
(
pht
(
'Unable to load repository with PHID "%s".'
,
$phid
));
}
}
$map
=
array
();
foreach
(
$also_phids
as
$also_phid
)
{
$also_repo
=
$repositories
[
$also_phid
];
$map
[
$also_repo
->
getCloneName
()]
=
array
(
'phid'
=>
$also_repo
->
getPHID
(),
'branch'
=>
'master'
,
);
}
$repository
=
$repositories
[
$repository_phid
];
$commit
=
idx
(
$variables
,
'repository.commit'
);
$ref_uri
=
idx
(
$variables
,
'repository.staging.uri'
);
$ref_ref
=
idx
(
$variables
,
'repository.staging.ref'
);
if
(
$commit
)
{
$spec
=
array
(
'commit'
=>
$commit
,
);
}
else
if
(
$ref_uri
&&
$ref_ref
)
{
$spec
=
array
(
'ref'
=>
array
(
'uri'
=>
$ref_uri
,
'ref'
=>
$ref_ref
,
),
);
}
else
{
throw
new
Exception
(
pht
(
'Unable to determine how to fetch changes: this buildable does not '
.
'identify a commit or a staging ref. You may need to configure a '
.
'repository staging area.'
));
}
$directory
=
$repository
->
getCloneName
();
$map
[
$directory
]
=
array
(
'phid'
=>
$repository
->
getPHID
(),
'default'
=>
true
,
)
+
$spec
;
return
$map
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Tue, May 27, 8:48 AM (1 d, 12 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
170425
Default Alt Text
HarbormasterLeaseWorkingCopyBuildStepImplementation.php (5 KB)
Attached To
Mode
rP Phorge
Attached
Detach File
Event Timeline
Log In to Comment