{"size": 1029, "ext": "js", "max_stars_repo_path": "faas/resource-management-sink/app.js", "max_stars_repo_name": "FraunhoferISST/diva", "max_stars_repo_stars_event_min_datetime": "2021-07-12T08:50:43.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T06:39:30.000Z", "max_issues_repo_path": "faas/resource-management-sink/app.js", "max_issues_repo_name": "FraunhoferISST/diva-core", "max_issues_repo_issues_event_min_datetime": "2021-08-02T16:23:15.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T15:17:22.000Z", "max_forks_repo_path": "faas/resource-management-sink/app.js", "max_forks_repo_name": "FraunhoferISST/diva-core", "max_forks_repo_forks_event_min_datetime": "2021-09-11T11:50:52.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-08T22:48:29.000Z"}
{"max_stars_count": 15, "max_issues_count": 86, "max_forks_count": 2, "avg_line_length": 22.3695652174, "max_line_length": 71, "alphanum_fraction": 0.628765792}
const axios = require("axios");
const fs = require("fs-extra");
const urljoin = require("url-join");

const RESOURCE_MANAGEMENT_URL =
  process.env.RESOURCE_MANAGEMENT_URL || "localhost:3000";

const patchData = async () => {
  const resourceId = process.env.RESOURCE_ID;
  const content = fs.readFileSync(process.env.INPUT_FILE).toString();
  const parsed = JSON.parse(content);

  if (process.env.NODE_ENV === "development") {
    console.log(`Content to be patched: ${content}`);
  }

  if (Object.keys(parsed).length > 0) {
    const res = await axios.patch(
      urljoin(RESOURCE_MANAGEMENT_URL, "resources", resourceId),
      parsed,
      {
        headers: { "x-actorid": process.env.ACTOR_ID },
      }
    );

    return res;
  }

  console.log(
    `❗ Discard empty Result: ${content} (this should not be a problem)`
  );

  return true;
};

patchData()
  .then((res) => {
    console.log(res);
    console.log("success");
    process.exit(0);
  })
  .catch((e) => {
    console.error(e);
    process.exit(1);
  });
