FabioPereiraBraga / gitlab-sync

plugin para o insomnia
MIT License
8 stars 8 forks source link

Impossible to push when file does not exists #6

Closed jervds closed 3 years ago

jervds commented 3 years ago

Hello,

I have just installed your plugin, and I have noticed some issues with it:

Kr, Jérôme

FabioPereiraBraga commented 3 years ago

correction performed, thanks

jorgebrunal commented 2 years ago

thank you very much for the Plugin!

Proposed changes New feature (non-breaking change which adds functionality) allow a check to be made to verify if the file exists and if it does not modify the files:

What are the steps to reproduce? allow the creation of the file in case it does not exist in the repo

What do you expect to happen? as reported by user @jervds :smile:

Please tell us about your environment: Insomnia 2022.3.0 insomnia-plugin-gitlab-sync v1.2.11 node.js version: v16.13.0 Platform/OS: Manjaro 21.2.4 Qonos

Full example:

index.js

{
    label: "GitLab - Push Collection",
    ...
    console.log("Push Collection");
    await loadProvider(context, models);
    // add the following lines
    // start
      var mode = "update";

      try {
          console.log("checking if the file exists...");
        await provider.check();
        console.log("yep, the file exists!, updating...");
      } catch (e) {
          console.log("fail, the file does not exist...", e);
        mode = "create";
      }
    // end

      update(context, models, mode); // send the new mode
    }
}

gitlab.js

//new function to check
async check() {
    try {
      const response = await axios.get(
        `${this.config.api_url}/api/v4/projects/${this.config.id_project}/repository/files/${this.config.name_file}?ref=${this.config.ref}&private_token=${this.config.token}`
      );
      return response.data;
    } catch (e) {
      throw `Collection query failed for informed project ${this.config.id_project}`;
    }
  }

// new parameter: mode
async update(content, messageCommit, mode) {
    // add the following lines
    // start
        actions: [
          {
            action: mode || "update",
          },
        ],
    // end
  }

I have found that the Gitlab Api does not have a simple way to check if a file exists, it uses the same endpoind that you use in the get function, without the raw parameter.

more info: Gitlab Api - Get file from repository

my apologies for the translation, I do not speak English.

thanks!