Skip to content

Commit

Permalink
Issue #37: Add ability for other modules to modify files from the Pac…
Browse files Browse the repository at this point in the history
…kager.
  • Loading branch information
docwilmot authored and quicksketch committed Aug 27, 2019
1 parent 7f86eae commit 237bd74
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
29 changes: 29 additions & 0 deletions project_github/project_github.api.php
Expand Up @@ -70,3 +70,32 @@ function hook_github_project_validate_release(Node $release_node, array &$errors
$errors['project_type_invalid'] = t('Project releases are only supported on module projects.');
}
}

/**
* Modify the contents of the GitHub webhook payload.
*
* @param $project_name
* The name of the project.
* @param array $files
* An array representing the files in the payload directory after the payload
* has been unzipped, and the original zip file deleted, and before the new
* archive is created and resent to GitHub.
* @return NULL
* No return value.
*/
function hook_project_github_create_package_alter(array &$files, $project_name) {
foreach ($files as $path => $file) {
$extension = substr($file->filename, strrpos($file->filename, '.') + 1);
if ($extension === 'info' && $file->name == $project_name) {
$directory_path = rtrim($path, $file->filename);
if (is_dir($directory_path . 'screenshots')) {
$screenshots_directory_path = $directory_path . 'screenshots/';
}
}
}
foreach ($files as $path => $file) {
if (strrpos($path, $screenshots_directory_path) === 0) {
unset($files[$path]);
}
}
}
3 changes: 3 additions & 0 deletions project_github/project_github.pages.inc
Expand Up @@ -53,6 +53,9 @@ function _project_github_create_package(array &$errors, array &$payload) {
// Make a list of all files sans the archive.
$files = file_scan_directory($directory, '/.*/', array('nomask' => '/^$/'));

// Allow other modules to modify the files.
backdrop_alter('project_github_create_package', $files, $project_name);

// Individually rezip each file, modifying .info files as needed.
$archive = new ZipArchive();
$archive_name = $project_name . '.zip';
Expand Down

0 comments on commit 237bd74

Please sign in to comment.