guibranco / gstraccini-bot

🤖 :octocat: A GitHub bot that runs on issues, pull requests, and pull request comments
https://bot.straccini.com
MIT License
2 stars 0 forks source link

[FEATURE] Detect SemVer changes in `appveyor.yml` and recommend build number reset #499

Open guibranco opened 1 week ago

guibranco commented 1 week ago

Description

We need to implement a feature that parses pull request content to detect if the version specified in the appveyor.yml file has changed. If a change is detected, the system should recommend running a command to reset the build number, ensuring accurate versioning and build consistency.

Problem Statement

Proposed Solution

Implementation Steps

  1. Fetch Pull Request Details:

    • Use the GitHub REST API to fetch the content of the pull request and the changes made to appveyor.yml.
    $repoOwner = 'your-repo-owner';
    $repoName = 'your-repo-name';
    $pullRequestNumber = 'your-pr-number';
    $token = 'your-github-token';
    
    $url = "https://api.github.com/repos/$repoOwner/$repoName/pulls/$pullRequestNumber/files";
    $options = [
       "http" => [
           "header" => "Authorization: token $token\r\nUser-Agent: YourApp\r\n",
           "method" => "GET",
       ],
    ];
    $context = stream_context_create($options);
    $response = file_get_contents($url, false, $context);
    $files = json_decode($response, true);
  2. Check for Version Changes:

    • Parse the response to identify changes to appveyor.yml and compare the old and new version numbers.
    foreach ($files as $file) {
       if ($file['filename'] === 'appveyor.yml') {
           $patch = $file['patch'];
           // Parse the patch to check for version changes
           if (strpos($patch, 'version:') !== false) {
               // Extract the old and new version numbers
               // Implement your logic to determine if the version has changed
               $versionChanged = true; // Example condition
               if ($versionChanged) {
                   // Recommend resetting the build number
                   $comment = "The version number in `appveyor.yml` has been updated. It is recommended to run the following command to reset the build number:\n\n```bash\nappveyor build restart --build-number <new-build-number>\n```";
                   // Post a comment on the pull request
                   postComment($repoOwner, $repoName, $pullRequestNumber, $comment, $token);
               }
           }
       }
    }
    
    function postComment($owner, $repo, $prNumber, $comment, $token) {
       $url = "https://api.github.com/repos/$owner/$repo/issues/$prNumber/comments";
       $data = json_encode(['body' => $comment]);
       $options = [
           "http" => [
               "header" => "Authorization: token $token\r\nContent-Type: application/json\r\nUser-Agent: YourApp\r\n",
               "method" => "POST",
               "content" => $data,
           ],
       ];
       $context = stream_context_create($options);
       file_get_contents($url, false, $context);
    }
  3. Testing:

    • Test the script to ensure it accurately detects version changes and posts appropriate recommendations.
  4. Documentation:

    • Document the new feature, including instructions on how to use it and any configuration required.

Additional Notes

gitauto-ai[bot] commented 1 week ago

Hello @guibranco, you have reached your request limit of 5, your cycle will refresh on 2024-09-21 10:07:38+00:00. Consider subscribing if you want more requests. If you have any questions or concerns, please contact us at info@gitauto.ai.