#3002 pagure_ci: Strip trailing slashes instead of splitting the string to get the jenkins_name
Closed 6 years ago by pingou. Opened 6 years ago by bstinson.
bstinson/pagure jobsplit-pagure_ci  into  master

@@ -96,7 +96,7 @@ 

  

              # Jenkins Base URL

              base_url, name = url.split('/job/', 1)

-             jenkins_name = name.split('/', 1)[0]

+             jenkins_name = name.rstrip('/')

  

              data = {

                  'cause': pr_id,

Jenkins jobnames can have slashes in them (yay). So doing str.split() may
only get you a substring of the actual jobname.

@pingou: thoughts on split() vs rstrip()

yay indeed :/

But these two lines are not quite doing the same thing:

>>> 'foo/bar'.rstrip('/')
'foo/bar'
>>> 'foo/bar'.split('/', 1)[0]
'foo'

So I'm not sure what we want to do there :-s

Yep, they aren't quite the same thing because we need the whole string in jenkins_name. In your example foo/bar is the name of the job we trigger, but in the current state pagure_ci would only try to trigger a job called foo

I'm thinking the purpose of doing the split() was to take off trailing slashes that may have lingered in the jobname even though we call rstrip() on the URL earlier in the source.

Consider the following job:

>>> url = 'https://jenkins-fedora-docs.apps.ci.centos.org/job/fedora-docs/job/fedora-docs-development-pipeline/'
>>> base_url, name = url.split('/job/',1)
>>> name
'fedora-docs/job/fedora-docs-development-pipeline'

If we do str.split():

>>> jenkins_name = name.split('/', 1)[0]
>>> jenkins_name
'fedora-docs'

Because

>>> name.split('/',1)
['fedora-docs', 'job/fedora-docs-development-pipeline']

What we -actually- want is:

>>> jenkins_name  = name.rstrip('/')  
>>> jenkins_name
'fedora-docs/job/fedora-docs-development-pipeline'

'fedora-docs/job/fedora-docs-development-pipeline' we also have to remove /job/ from this otherwise Jenkins is not happy

so the jobname should be 'fedora-docs/fedora-docs-development-pipeline'

Removing the /job/ part is a matter of .replace('/job/', '/') doable, but starts to feel a little messy no?

If it's what we got to do, we got to do it but :s

Maybe we could get the jobname from the settings, by adding another input box to the form. That should support all use cases.

+1 for @cverna on this, but I feel it will be way too much setting to add a job-name, if we could automate it or if there is a way to fetch job name.

@cverna re-designed the pagure-ci integration in https://pagure.io/pagure/pull-request/3074 which I believe makes this PR no longer necessary.

So closing it :)

Pull-Request has been closed by pingou

6 years ago
Metadata