Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-41403

Additions to Github APIs for Organizations and Repositories

    • Icon: Improvement Improvement
    • Resolution: Fixed
    • Icon: Minor Minor
    • blueocean-plugin
    • None
    • pannonian, iapetus

      I would like to request two additions to the Github APIs.

      When listing organizations via /jenkins/scm/github/organizations/?credentialId=github the response is currently:

      [{
          "_class": "io.jenkins.blueocean.blueocean_github_pipeline.GithubOrganization",
          "_links": {
              "repositories": {
                  "_class": "io.jenkins.blueocean.rest.hal.Link",
                  "href": "/organizations/jenkins/scm/github/organizations/jenkinsci/repositories/"
              },
              "self": {
                  "_class": "io.jenkins.blueocean.rest.hal.Link",
                  "href": "/organizations/jenkins/scm/github/organizations/jenkinsci/"
              }
          },
          "avatar": "https://avatars.githubusercontent.com/u/107424?v=3&s=50",
          "jenkinsOrganizationPipeline": false,
          "name": "jenkinsci"
      }, {
          "_class": "io.jenkins.blueocean.blueocean_github_pipeline.GithubUserOrganization",
          "_links": {
              "repositories": {
                  "_class": "io.jenkins.blueocean.rest.hal.Link",
                  "href": "/organizations/jenkins/scm/github/organizations/cliffmeyers/repositories/"
              },
              "self": {
                  "_class": "io.jenkins.blueocean.rest.hal.Link",
                  "href": "/organizations/jenkins/scm/github/organizations/cliffmeyers/"
              }
          },
          "avatar": "https://avatars.githubusercontent.com/u/143466?v=3&s=50",
          "jenkinsOrganizationPipeline": true,
          "name": "cliffmeyers"
      }, {
          "_class": "io.jenkins.blueocean.blueocean_github_pipeline.GithubOrganization",
          "_links": {
              "repositories": {
                  "_class": "io.jenkins.blueocean.rest.hal.Link",
                  "href": "/organizations/jenkins/scm/github/organizations/cloudbees/repositories/"
              },
              "self": {
                  "_class": "io.jenkins.blueocean.rest.hal.Link",
                  "href": "/organizations/jenkins/scm/github/organizations/cloudbees/"
              }
          },
          "avatar": "https://avatars.githubusercontent.com/u/235526?v=3&s=50",
          "jenkinsOrganizationPipeline": false,
          "name": "cloudbees"
      }]
      

      1. For organizations where jenkinsOrganizationPipeline is true, could we add an additional field that indicates whether "auto discover" is enabled? This is equivalent to a Github org folder that was created without specifying any repository names (i.e. empty "repoNames" array)

      2. For organizations where jenkinsOrganizationPipeline is true, could we also add a HAL link to the Jenkins org folder? This will make REST API update calls much easier.

      When listing repositories via /jenkins/scm/github/organizations/cliffmeyers/repositories/?credentialId=github&pageNumber=1&pageSize=100 the response is currently:

      {
          "_class": "io.jenkins.blueocean.blueocean_github_pipeline.GithubRespositoryContainer",
          "_links": {
              "self": {
                  "_class": "io.jenkins.blueocean.rest.hal.Link",
                  "href": "/organizations/jenkins/scm/github/organizations/cliffmeyers/repositories/"
              }
          },
          "repositories": {
              "_class": "io.jenkins.blueocean.blueocean_github_pipeline.GithubRepositories",
              "_links": {
                  "self": {
                      "_class": "io.jenkins.blueocean.rest.hal.Link",
                      "href": "/organizations/jenkins/scm/github/organizations/cliffmeyers/repositories/repositories/"
                  }
              },
              "items": [{
                  "_class": "io.jenkins.blueocean.blueocean_github_pipeline.GithubRepository",
                  "_links": {
                      "self": {
                          "_class": "io.jenkins.blueocean.rest.hal.Link",
                          "href": "/organizations/jenkins/scm/github/organizations/cliffmeyers/repositories/repositories/blog-examples/"
                      }
                  },
                  "defaultBranch": "master",
                  "description": "Sample code from stuff on my blog",
                  "name": "blog-examples",
                  "permissions": {
                      "admin": true,
                      "push": true,
                      "pull": true
                  },
                  "private": false,
                  "fullName": "cliffmeyers/blog-examples"
              }, {
                  "_class": "io.jenkins.blueocean.blueocean_github_pipeline.GithubRepository",
                  "_links": {
                      "self": {
                          "_class": "io.jenkins.blueocean.rest.hal.Link",
                          "href": "/organizations/jenkins/scm/github/organizations/cliffmeyers/repositories/repositories/blueocean-plugin/"
                      }
                  },
                  "defaultBranch": "master",
                  "description": "Blue Ocean UI app",
                  "name": "blueocean-plugin",
                  "permissions": {
                      "admin": true,
                      "push": true,
                      "pull": true
                  },
                  "private": false,
                  "fullName": "cliffmeyers/blueocean-plugin"
              }, {
                  "_class": "io.jenkins.blueocean.blueocean_github_pipeline.GithubRepository",
                  "_links": {
                      "self": {
                          "_class": "io.jenkins.blueocean.rest.hal.Link",
                          "href": "/organizations/jenkins/scm/github/organizations/cliffmeyers/repositories/repositories/frontend-maven-plugin/"
                      }
                  },
                  "defaultBranch": "master",
                  "description": "\"Maven-node-grunt-gulp-npm-node-plugin to end all maven-node-grunt-gulp-npm-plugins.\" A Maven plugin that downloads/installs Node and NPM locally, runs NPM install, Grunt, Gulp and/or Karma.",
                  "name": "frontend-maven-plugin",
                  "permissions": {
                      "admin": true,
                      "push": true,
                      "pull": true
                  },
                  "private": false,
                  "fullName": "cliffmeyers/frontend-maven-plugin"
              }, {
                  "_class": "io.jenkins.blueocean.blueocean_github_pipeline.GithubRepository",
                  "_links": {
                      "self": {
                          "_class": "io.jenkins.blueocean.rest.hal.Link",
                          "href": "/organizations/jenkins/scm/github/organizations/cliffmeyers/repositories/repositories/java-utils/"
                      }
                  },
                  "defaultBranch": "master",
                  "description": "Utilities for Java",
                  "name": "java-utils",
                  "permissions": {
                      "admin": true,
                      "push": true,
                      "pull": true
                  },
                  "private": false,
                  "fullName": "cliffmeyers/java-utils"
              }],
              "lastPage": 3,
              "nextPage": 2,
              "pageSize": 4
          }
      }
      

      3. Could we add a field to the repository object that indicates whether a pipeline has already been created for it? This is important in the "update" scenario to avoid the user trying to create a repo that was already created.

          [JENKINS-41403] Additions to Github APIs for Organizations and Repositories

          Michael Neale added a comment -

          Yes that is right. And the assumption is that the name of the org is the name of the top level org folder item so that the UI knows what to look up to fetch what repos are setup etc.

          Michael Neale added a comment - Yes that is right. And the assumption is that the name of the org is the name of the top level org folder item so that the UI knows what to look up to fetch what repos are setup etc.

          Cliff Meyers added a comment -

          I am in agreement: this looks good.

          Cliff Meyers added a comment - I am in agreement: this looks good.

          Vivek Pandey added a comment -

          michaelneale cliffmeyers requestedRepos is saved as pattern using underlying GitHub-branch-source library. If you create org pipeline using BO creation flow there is way to get list of requested repo (BO api saves list of requested repos as properties on the org folder).

          However users can create org pipeline using classic and give any kind of regex pattern and its not possible to get meaningful list of repositories. Basically, if its created using classic, this field is going to be empty but that might get interpreted as auto-scanned.

          So is it reasonable behavior that "requestedRepos" element is present only if org folder was created using BO GitHub creation flow?

          Vivek Pandey added a comment - michaelneale cliffmeyers requestedRepos is saved as pattern using underlying GitHub-branch-source library. If you create org pipeline using BO creation flow there is way to get list of requested repo (BO api saves list of requested repos as properties on the org folder). However users can create org pipeline using classic and give any kind of regex pattern and its not possible to get meaningful list of repositories. Basically, if its created using classic, this field is going to be empty but that might get interpreted as auto-scanned. So is it reasonable behavior that "requestedRepos" element is present only if org folder was created using BO GitHub creation flow?

          Michael Neale added a comment -

          vivek if we can discriminate between if it was created by blue ocean or not* - sure. Perhaps could be another field? I would leave it to cliffmeyers. However, I think it is probably fine to omit it.

          What about the case that it was created by blue ocean originally, but a user tweaks the regex after the fact - it would then be invalidated and we would have to know somehow - is this possible?

          • Is it necessary to be a property - as if it is a list of patterns, it is pretty clear that it is a list (ie space separated right? or not reasonable to reverse it out of the pattern?)

          Michael Neale added a comment - vivek if we can discriminate between if it was created by blue ocean or not* - sure. Perhaps could be another field? I would leave it to cliffmeyers . However, I think it is probably fine to omit it. What about the case that it was created by blue ocean originally, but a user tweaks the regex after the fact - it would then be invalidated and we would have to know somehow - is this possible? Is it necessary to be a property - as if it is a list of patterns, it is pretty clear that it is a list (ie space separated right? or not reasonable to reverse it out of the pattern?)

          Vivek Pandey added a comment -

          michaelneale cliffmeyers Actually I don't see how it can work in all cases no matter which way we go. Internally its represented as pattern that user can tweak as well in classic. So there is no guarunteed round trip. I propose to drop requestedRepos property as there doesn't seem a way to provide that in consistent way.

          Vivek Pandey added a comment - michaelneale cliffmeyers Actually I don't see how it can work in all cases no matter which way we go. Internally its represented as pattern that user can tweak as well in classic. So there is no guarunteed round trip. I propose to drop requestedRepos property as there doesn't seem a way to provide that in consistent way.

          Cliff Meyers added a comment -

          If we drop "requestedRepos" we can't determine whether the user originally picked "autodiscover" or "one repo" and this has a profound implication on what we can do with the re-entrant flow for Github Creation. Seems appropriate to pull jamesdumay into this conversation as he had originally conceived of the feature.

          Cliff Meyers added a comment - If we drop "requestedRepos" we can't determine whether the user originally picked "autodiscover" or "one repo" and this has a profound implication on what we can do with the re-entrant flow for Github Creation. Seems appropriate to pull jamesdumay into this conversation as he had originally conceived of the feature.

          Vivek Pandey added a comment -

          cliffmeyers Ok, so all you need is to determine auto-discover or not. How about backend API returns a boolean - I was trying to avoid that but this seems like most logical solution given challenges listing requested repos. Sounds good to you?

          Vivek Pandey added a comment - cliffmeyers Ok, so all you need is to determine auto-discover or not. How about backend API returns a boolean - I was trying to avoid that but this seems like most logical solution given challenges listing requested repos. Sounds good to you?

          Cliff Meyers added a comment -

          Per discussion, boolean flag is okay as long as the "pipelines" array is preserved. This is important when a user wants to transition from "auto-discover" to "single repo" so that we can call the "update" REST API and provide accurate list for "repoNames": [].concat(pipelines, newRepoName)

          Cliff Meyers added a comment - Per discussion, boolean flag is okay as long as the "pipelines" array is preserved. This is important when a user wants to transition from "auto-discover" to "single repo" so that we can call the "update" REST API and provide accurate list for "repoNames": [].concat(pipelines, newRepoName)

          James Dumay added a comment -

          cliffmeyers vivek not sure what I should be chiming in here for?

          James Dumay added a comment - cliffmeyers vivek not sure what I should be chiming in here for?

          Cliff Meyers added a comment -

          jamesdumay Vivek and I chatted earlier and sorted this out; we're all good for now.

          Cliff Meyers added a comment - jamesdumay Vivek and I chatted earlier and sorted this out; we're all good for now.

            vivek Vivek Pandey
            cliffmeyers Cliff Meyers
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: