Skip to content

GitHub App Tutorial (Part 3)

Posted on:May 4, 2023 at 05:22 PM

General overview of the flow

This article will go through in 3 parts

  1. Install packages
yarn add oci-sdk
yarn add oci-common
yarn add xml-parser
  1. Update index.js
/**
 * This is the main entrypoint to your Probot app
 * @param {import('probot').Probot} app
 */
const parse = require("xml-parser");

// JavaScript
const common = require("oci-common");
// Using default configurations
const provider = new common.ConfigFileAuthenticationDetailsProvider();
const jms = require("oci-jms");

const OWNER = "lanbau";
const REPO = "sample-java-project";
const PATH = "pom.xml";

module.exports = app => {
  app.log.info("Yay, the app was loaded!");

  app.on("push", async context => {
    app.log.info({ event: context.name, action: context.payload.action });

    try {
      context.octokit.rest.repos
        .getContent({
          owner: OWNER,
          repo: REPO,
          path: PATH,
        })
        .then(res => {
          const pomData = atob(res.data.content);
          const obj = parse(pomData);
          const javaVersion = obj.root.children[7].children[5].content;
          const client = new jms.JavaManagementServiceClient({
            authenticationDetailsProvider: provider,
          });

          (async () => {
            try {
              // Create a request and dependent object(s).
              const getJavaReleaseRequest = {
                releaseVersion: javaVersion,
                opcRequestId: "GMT4UEGUMOLHIUHPFJNG123",
              };

              // Send request to the Client.
              const getJavaReleaseResponse = await client.getJavaRelease(
                getJavaReleaseRequest
              );

              context.octokit.rest.issues.create({
                owner: OWNER,
                repo: REPO,
                title:
                  javaVersion +
                  " Security Baseline: " +
                  getJavaReleaseResponse.javaRelease.securityStatus,
                body: `<ul>
                <li>Release version: ${getJavaReleaseResponse.javaRelease.releaseVersion}</li>
                <li>Family version: ${getJavaReleaseResponse.javaRelease.familyVersion}</li>
                <li>Parent release version: ${getJavaReleaseResponse.javaRelease.parentReleaseVersion}</li>
                <li>License type: ${getJavaReleaseResponse.javaRelease.licenseType}</li>
                <li>Release date: ${getJavaReleaseResponse.javaRelease.releaseDate}</li>
                <li>Release notes URL: ${getJavaReleaseResponse.javaRelease.releaseNotesUrl}</li>
              </ul>`,
              });
            } catch (error) {
              console.log("getJavaRelease Failed with error  " + error);
            }
          })();
        });
    } catch (err) {
      console.log(err);
    }
  });
};
  1. Update Permissions of GitHub application to read contents and listen to push event
GitHub Application Tutorial GitHub Application Tutorial
  1. Go to sample-java-project & make a change
GitHub Application Tutorial GitHub Application Tutorial

You can clone the sample project at https://github.com/lanbau/sample-java-project/

  1. Go to the demo project’s issues.

You will see that the GitHub application has automatically created an issue in the demo project.

There are more details within the issue description which is provided by Java Management Service.

GitHub Application Tutorial GitHub Application Tutorial

This is the end of the GitHub app tutorial that demonstrate integration with Oracle’s Java Management Service.

Source Code