Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
afragen committed Jan 8, 2025
2 parents 316ae29 + 6f555bb commit c488242
Show file tree
Hide file tree
Showing 16 changed files with 542 additions and 251 deletions.
68 changes: 68 additions & 0 deletions .github/workflows/generate-pot-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Generate POT PR

on:
workflow_dispatch:
push:
branches:
- main
- master

jobs:
generate-pot:
name: Generate POT PR
if: github.repository == "${{ github.event.repository.full_name }}"
permissions:
contents: write
pull-requests: write
runs-on: ubuntu-latest
steps:
- name: Check out source code
uses: actions/checkout@v4

- name: Set up PHP environment
uses: shivammathur/setup-php@v2
with:
php-version: "7.4"

- name: Setup WP-CLI
uses: godaddy-wordpress/setup-wp-cli@1

- name: Configure git user
run: |
git config --global user.email "[email protected]"
git config --global user.name "Andy Fragen"
- name: Check if remote branch exists
run: echo "REMOTE_BRANCH_EXISTS=$([[ -z $(git ls-remote --heads origin generate-pot) ]] && echo "0" || echo "1")" >> $GITHUB_ENV

- name: Create branch to base pull request on
if: env.REMOTE_BRANCH_EXISTS == 0
run: |
git checkout -b generate-pot
- name: Fetch existing branch to add commits to
if: env.REMOTE_BRANCH_EXISTS == 1
run: |
git fetch --all --prune
git checkout generate-pot
git pull --no-rebase
- name: Generate POT
run: |
wp i18n make-pot . "./languages/${{ github.event.repository.name }}.pot" --headers='{"Report-Msgid-Bugs-To":"https://github.com/${{ github.event.repository.full_name }}/issues"}'
- name: Check if there are changes
run: echo "CHANGES_DETECTED=$([[ -z $(git status --porcelain) ]] && echo "0" || echo "1")" >> $GITHUB_ENV

- name: Commit changes
if: env.CHANGES_DETECTED == 1
run: |
git add "./languages/${{ github.event.repository.name }}.pot"
git commit -m "Generate POT - $(date +'%Y-%m-%d')"
git push origin generate-pot
- name: Create pull request
if: env.CHANGES_DETECTED == 1
run: gh pr create --base main --head generate-pot --title "Generate POT - $(date +'%Y-%m-%d')" --body "Automated PR"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
25 changes: 0 additions & 25 deletions .github/workflows/generate-pot.yml

This file was deleted.

9 changes: 9 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
#### [unreleased]

#### 12.9.0 / 2025-01-07
* add API get for repo root contents for efficiency
* add feature to virtually add repos via Additions tab to server REST update-api endpoint
* switch to getting most data via API calls and not from locally installed files
* add REST endpoint to individually flush repo cache
* fix `Basic_Auth_Loader::get_slug_for_credentials()` to get slug for gist
* update `$release_asset_parts` in `Basic_Auth_Loader::unset_release_asset_auth()` for AWS download link
* improved release asset handling

#### 12.8.0 / 2024-12-21
* update GitHub release asset parsing
* update `REST_API` for Bitbucket update link
Expand Down
2 changes: 1 addition & 1 deletion git-updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* Plugin Name: Git Updater
* Plugin URI: https://git-updater.com
* Description: A plugin to automatically update GitHub hosted plugins, themes, and language packs. Additional API plugins available for Bitbucket, GitLab, Gitea, and Gist.
* Version: 12.8.0
* Version: 12.9.0
* Author: Andy Fragen
* License: MIT
* Domain Path: /languages
Expand Down
8 changes: 8 additions & 0 deletions src/Git_Updater/API/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,14 @@ protected function set_file_info( $response ) {
$this->type->requires = ! empty( $response['Requires'] ) ? $response['Requires'] : $this->type->requires;
$this->type->dot_org = $response['dot_org'];
$this->type->primary_branch = ! empty( $response['PrimaryBranch'] ) ? $response['PrimaryBranch'] : $this->type->primary_branch;
if ( ! isset( $this->type->name ) ) {
$this->type->name = $response['Name'];
$this->type->local_version = strtolower( $response['Version'] );
$this->type->author = $response['Author'];
$this->type->homepage = isset( $response['PluginURI'] ) ? $response['PluginURI'] : '';
$this->type->homepage = isset( $response['ThemeURI'] ) ? $response['ThemeURI'] : $this->type->homepage;
$this->type->sections['description'] = $response['Description'];
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Git_Updater/API/API_Interface.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function get_remote_tag();
*
* @access public
*
* @param string $changes Changelog filename.
* @param string $changes Changelog filename - (deprecated).
*
* @return mixed
*/
Expand Down
86 changes: 79 additions & 7 deletions src/Git_Updater/API/GitHub_API.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,18 @@ public function get_remote_info( $file ) {
* @return bool
*/
public function get_remote_tag() {
return $this->get_remote_api_tag( '/repos/:owner/:repo/tags' );
return $this->get_remote_api_tag( 'github', '/repos/:owner/:repo/tags' );
}

/**
* Read the remote CHANGES.md file.
*
* @param string $changes Changelog filename.
* @param string $changes The changelog filename - deprecated.
*
* @return bool
*/
public function get_remote_changes( $changes ) {
return $this->get_remote_api_changes( 'github', $changes, "/repos/:owner/:repo/contents/{$changes}" );
return $this->get_remote_api_changes( 'github', $changes, '/repos/:owner/:repo/contents/:changelog' );
}

/**
Expand All @@ -78,7 +78,7 @@ public function get_remote_changes( $changes ) {
* @return bool|void
*/
public function get_remote_readme() {
$this->get_remote_api_readme( 'github', '/repos/:owner/:repo/contents/readme.txt' );
$this->get_remote_api_readme( 'github', '/repos/:owner/:repo/contents/:readme' );
}

/**
Expand All @@ -87,7 +87,7 @@ public function get_remote_readme() {
* @return bool
*/
public function get_repo_meta() {
return $this->get_remote_api_repo_meta( '/repos/:owner/:repo' );
return $this->get_remote_api_repo_meta( 'github', '/repos/:owner/:repo' );
}

/**
Expand All @@ -108,6 +108,24 @@ public function get_release_asset() {
return $this->get_api_release_asset( 'github', '/repos/:owner/:repo/releases/latest' );
}

/**
* Return list of repository assets.
*
* @return array
*/
public function get_repo_assets() {
return $this->get_remote_api_assets( 'github', '/repos/:owner/:repo/contents/:path' );
}

/**
* Return list of files at repo root.
*
* @return array
*/
public function get_repo_contents() {
return $this->get_remote_api_contents( 'github', '/repos/:owner/:repo/contents' );
}

/**
* Construct $this->type->download_link using Repository Contents API.
*
Expand Down Expand Up @@ -172,6 +190,7 @@ public function add_endpoints( $git, $endpoint ) {
switch ( $git::$method ) {
case 'file':
case 'readme':
case 'assets':
case 'changes':
$endpoint = add_query_arg( 'ref', $git->type->branch, $endpoint );
break;
Expand Down Expand Up @@ -329,8 +348,8 @@ public function parse_release_asset_response( $response ) {
if ( $this->validate_response( $response ) ) {
return;
}
if ( property_exists( $response, 'browser_download_url' ) ) {
$this->set_repo_cache( 'release_asset_download', $response->browser_download_url );
if ( property_exists( $response, 'url' ) ) {
$this->set_repo_cache( 'release_asset_download', $response->url );
}
}

Expand Down Expand Up @@ -364,6 +383,59 @@ protected function parse_tags( $response, $repo_type ) {
return [ $tags, $rollback ];
}

/**
* Parse remote root files/dirs.
*
* @param \stdClass|array $response Response from API call.
*
* @return array
*/
protected function parse_contents_response( $response ) {
$files = [];
$dirs = [];
foreach ( $response as $content ) {
if ( 'file' === $content->type ) {
$files[] = $content->name;
}
if ( 'dir' === $content->type ) {
$dirs[] = $content->name;
}
}

return [
'files' => $files,
'dirs' => $dirs,
];
}

/**
* Parse remote assets directory.
*
* @param \stdClass|array $response Response from API call.
*
* @return \stdClass|array
*/
protected function parse_asset_dir_response( $response ) {
$assets = [];

if ( isset( $response->message ) || is_wp_error( $response ) ) {
return $response;
}

foreach ( $response as $asset ) {
if ( 'file' === $asset->type ) {
$assets[ $asset->name ] = $asset->download_url;
}
}

if ( empty( $assets ) ) {
$assets['message'] = 'No assets found';
$assets = (object) $assets;
}

return $assets;
}

/**
* Add settings for GitHub Personal Access Token.
*
Expand Down
6 changes: 4 additions & 2 deletions src/Git_Updater/Additions/Additions.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,16 @@ public function add_headers( $config, $repos, $type ) {
$file_path = 'plugin' === $repo_type ? WP_PLUGIN_DIR . "/{$repo['slug']}" : null;
$file_path = 'theme' === $repo_type ? get_theme_root() . "/{$repo['slug']}/style.css" : $file_path;

if ( ! file_exists( $file_path ) || $type !== $repo_type ) {
if ( $type !== $repo_type ) {
continue;
}

$all_headers = Singleton::get_instance( 'Base', $this )->get_headers( $repo_type );

$additions[ $repo['slug'] ]['type'] = $repo_type;
$additions[ $repo['slug'] ] = get_file_data( $file_path, $all_headers );
if ( file_exists( $file_path ) ) {
$additions[ $repo['slug'] ] = get_file_data( $file_path, $all_headers );
}

switch ( $repo['type'] ) {
case 'github_plugin':
Expand Down
Loading

0 comments on commit c488242

Please sign in to comment.