diff --git a/cli/diff-changelog.php b/cli/diff-changelog.php index a0ae4cb..a2dc4d8 100755 --- a/cli/diff-changelog.php +++ b/cli/diff-changelog.php @@ -1,186 +1,186 @@ #!/usr/bin/php setConduitToken( CONDUIT_API_TOKEN ); $tasks = []; $tasks_phid = []; // cache with users by phids $USERS_BY_PHID = []; // https://gitpull.it/conduit/method/edge.search/ $edge_api_parameters = [ 'sourcePHIDs' => [ $diff_id ], 'types' => [ 'revision.task' ], ]; // find Tasks attached to Diff patch $edge_result = $client->callMethodSynchronous( 'edge.search', $edge_api_parameters ); foreach( $edge_result['data'] as $data ) { $tasks_phid[] = $data['destinationPHID']; } // https://gitpull.it/conduit/method/maniphest.search/ $maniphest_api_parameters = [ 'constraints' => [ 'phids' => $tasks_phid, ], ]; // query Tasks info $maniphest_result = $client->callMethodSynchronous( 'maniphest.search', $maniphest_api_parameters ); foreach( $maniphest_result['data'] as $task ) { // append in known Tasks $tasks[] = $task; // remember User PHIDs since we will need to get their extra info $phid_task_author = $task['fields']['authorPHID']; $phid_task_owner = $task['fields']['ownerPHID']; $USERS_BY_PHID[ $phid_task_author ] = null; $USERS_BY_PHID[ $phid_task_owner ] = null; } // get users info from their PHID identifiers $users_phid = array_keys( $USERS_BY_PHID ); $users_api_parameters = [ 'constraints' => [ 'phids' => $users_phid, ], ]; $users_result = $client->callMethodSynchronous( 'user.search', $users_api_parameters ); foreach( $users_result['data'] as $user_data ) { $phid_user = $user_data['phid']; $USERS_BY_PHID[ $phid_user ] = $user_data; } // for each language foreach( $I18N as $lang => $msg ) { $changelog_blocks = []; // NOTE: Phabricator has custom fields that can be populated to retrieve the changelog // in the specified language $phab_maniphest_custom_field_changelog = sprintf( PHABRICATOR_MANIPHEST_CUSTOM_FIELD_CHANGELOG, $lang ); // for each Task foreach( $tasks as $task ) { $task_id = $task['id']; $task_name = $task['fields']['name']; $task_descr = $task['fields']['description']; $phid_task_author = $task['fields']['authorPHID']; $phid_task_owner = $task['fields']['ownerPHID']; $author = $USERS_BY_PHID[ $phid_task_author ]; $owner = $USERS_BY_PHID[ $phid_task_owner ]; $username_author = $author['fields']['username']; $username_owner = $owner ['fields']['username']; $realname_author = $author['fields']['realName'] ?? null; $realname_owner = $owner ['fields']['realName'] ?? null; $task_url = PHABRICATOR_HOME . "T{$task_id}"; $url_author = PHABRICATOR_HOME . 'p/' . $username_author; $url_owner = PHABRICATOR_HOME . 'p/' . $username_owner; // get the most appropriate changelog field or the Task name $changelog_title = $task['fields'][$phab_maniphest_custom_field_changelog] ?? $task_name; // just try to show something useful for a F-Droid changelog $changelog_lines = []; // Task name and URL $changelog_lines[] = $task_name; // reporter by (author) $changelog_lines[] = sprintf( $msg['reportedByName'], $username_author ); // resolved by (owner) $changelog_lines[] = sprintf( $msg['resolvedByName'], $username_owner ); $changelog_lines[] = $task_url; $changelog_block = implode( "\n", $changelog_lines ); $changelog_blocks[] = $changelog_block; } // print all changelog blocks $changelog_content = implode( "\n\n", $changelog_blocks ); // expected changelog file $changelog_path = REPO_PATH . "/metadata/{$lang}/changelogs/{$version_code}.txt"; // save file_put_contents( $changelog_path, $changelog_content ); }