Skip to content

Implement multi-file commits #158

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed

Conversation

SautdeChat
Copy link

First, thanks for the API, it has been super helpful to my current project.

< backstory>
I have recently updated my GitLab and noticed an super helpful feature: Committing multiple files at once!
Until now I have been running a loop to add files to a repository. But this will create problems for runners (queuing up multiple for each single-file commit) which means in addition, I would have to remove and re-add the ci.yml.
<\backstory>

Anyway, they have added a new "Create a commit with multiple files and actions" option, and I have added a new function to Repositories.php to utilise it.
This new api call, however, requires JSON be sent, so I had to remove Your array typecasting in the httpclient. Not sure if this will upset something I am not currently using.

Here is how I am calling the new function and creating the data contents:
(Not sure if You would want to include an Action model somewhere?)

$files = ['install.yml', 'setup.yml'];

try {
    // Create the $actions array
    $actions = [];
    foreach ($files as $file) {
        // Make a new action class
        $action = new \stdClass();
        // Fill required properties
        $action->action = "update";
        $action->file_path = $file;
        $action->content = "Test Content";
        // Add to actions array
        array_push($actions, $action);
    }
    // Call actions function with required parameters
    // Is converted to JSON in actions()
    return GitLab::api('repo')->actions($id, $actions, 'develop', 'multipletest');
} catch (Exception $e) {
    $this->streamUpdate(0, $e->getMessage());
}

Let me know if I have to change anything. Or if it can be improved. =)

@fbourigault
Copy link
Contributor

Hello, thanks for your contribution! However, the master has evolved to use HTTPlug. Could you rework your PR to make it compatible?

@fbourigault fbourigault mentioned this pull request Aug 16, 2017
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants