eed-web-application / core-build-system

0 stars 0 forks source link

add new branch bug fix #28

Open pnispero opened 3 weeks ago

pnispero commented 3 weeks ago

There is a small bug with adding a new branch

specifically the PUT [/v1/component/{componentName}/branch] Create new branch of a component endpoint.

Problem

  1. Unable to add a new branch to existing component. Using the CLI, i created a request to create a new branch called 'dev-patrick'. But I get a return status of 500, saying 'error': 'Internal Server Error', 'path': '/v1/component/Oscilloscope/branch', 'errorCode': -1, 'errorMessage': 'The component is in use by other components'
  2. So looking at the code, in the service/ComponentService.java, function addNewBranch(). The first wrapCatch() checks to see if the component exists, if it doesn't then it throws an error The component is in use by other components. Which isn't an accurate error description, it should be 'component not found'. Anyways, the real issue is that for some reason the component isn't being found despite it being added to the database.

Request to see list of components:

pnispero@PC100942:~$  curl -X 'GET' \
  'https://ad-build-dev.slac.stanford.edu/api/cbs/v1/component' \
  -H 'accept: application/json'
{"errorCode":0,"payload":[{"id":"66aab0f508804932f1aec7cd","name":"test-ioc","url":"https://github.com/ad-build-test/test-ioc","description":"test ioc for testing build system"},{"id":"66c77f6a8e1d990df9188471","name":"buildsystem","url":"https://github.com/ad-build-test/BuildSystem.git","description":"AD build system repo"},{"id":"671ac7959d22bd1d90cacd89","name":"oscilloscope","url":"https://github.com/ad-build-test/Oscilloscope","description":"Oscilloscope app taken from /afs/slac.stanford.edu/g/cd/swe/git/repos/slac/Oscilloscopes/Oscilloscope.git"}]}

Request to see Oscilloscope component in detail:

pnispero@PC100942:~$ curl -X 'GET' \
  'https://ad-build-dev.slac.stanford.edu/api/cbs/v1/component/671ac7959d22bd1d90cacd89' \
  -H 'accept: application/json'
{"errorCode":0,"payload":{"id":"671ac7959d22bd1d90cacd89","name":"oscilloscope","description":"Oscilloscope app taken from /afs/slac.stanford.edu/g/cd/swe/git/repos/slac/Oscilloscopes/Oscilloscope.git","organization":"ad-build-test","url":"https://github.com/ad-build-test/Oscilloscope","approvalRule":"ALL","testingCriteria":"ALL","dependOn":[],"buildOs":["RHEL7"],"componentToken":"36ab26d3-cae6-4ab5-8801-a82a172381f5","versions":[],"branches":[],"createdDate":"2024-10-24T22:17:57.77","lastModifiedDate":"2024-10-24T22:17:57.77"}}

Possible solution

  1. I think the backend is not finding Oscilloscope because the O is not capitalized in the database. But when I made the component, I sent in a create new component request with a capital 'O' on the name.
    INFO-root:[request.py:40 - log_api_response() ] 201
    INFO-root:[request.py:41 - log_api_response() ] {'errorCode': 0, 'payload': '671ac7959d22bd1d90cacd89'}
    INFO-root:[request.py:42 - log_api_response() ] https://ad-build-dev.slac.stanford.edu/api/cbs/v1/component
    INFO-root:[request.py:43 - log_api_response() ] b'{"name": "Oscilloscope", "description": "Oscilloscope app taken from /afs/slac.stanford.edu/g/cd/swe/git/repos/slac/Oscilloscopes/Oscilloscope.git", "testingCriteria": "ALL", "approvalRule": "ALL", "organization": "ad-build-test", "buildOs": ["RHEL7"], "url": "https://github.com/ad-build-test/Oscilloscope"}'
  2. To check if it was really a simple character difference. I renamed my app, with a lowercase 'o' and tried to add the branch again and it worked.

    Original request with capital 'O'

    INFO-root:[request.py:40 - log_api_response() ] 500
    INFO-root:[request.py:41 - log_api_response() ] {'timestamp': '2024-10-24T22:51:10.232+00:00', 'status': 500, 'error': 'Internal Server Error', 'path': '/v1/component/Oscilloscope/branch', 'errorCode': -1, 'errorMessage': 'The component is in use by other components', 'errorDomain': None}
    INFO-root:[request.py:42 - log_api_response() ] https://ad-build-dev.slac.stanford.edu/api/cbs/v1/component/Oscilloscope/branch

    New request with lowercase 'o'

    INFO-root:[request.py:40 - log_api_response() ] 200
    INFO-root:[request.py:41 - log_api_response() ] {'errorCode': 0, 'payload': True}
    INFO-root:[request.py:42 - log_api_response() ] https://ad-build-dev.slac.stanford.edu/api/cbs/v1/component/oscilloscope/branch

    I think the backend somewhere forces the new component name to be all lowercase, which isn't a concern for many repos, but some repos do have uppercase letters. And that can be problematic.