Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bitbucket server example when both SSH and HTTPS enabled #1641

Merged
merged 1 commit into from
Sep 20, 2023

Conversation

khrm
Copy link
Contributor

@khrm khrm commented Sep 15, 2023

Fix the bitbucket server example when it has both SSH and HTTPS.

Changes

Submitter Checklist

As the author of this PR, please check off the items in this checklist:

  • Has Docs if any changes are user facing, including updates to minimum requirements e.g. Kubernetes version bumps
  • Has Tests included if any functionality added or changed
  • Follows the commit message standard
  • Meets the Tekton contributor standards (including functionality, content, code)
  • Has a kind label. You can add one by adding a comment on this PR that contains /kind <type>. Valid types are bug, cleanup, design, documentation, feature, flake, misc, question, tep
  • Release notes block below has been updated with any user facing changes (API changes, bug fixes, changes requiring upgrade notices or deprecation warnings). See some examples of good release notes.
  • Release notes contains the string "action required" if the change requires additional action from users switching to the new release

Release Notes

NONE

@tekton-robot tekton-robot added the release-note-none Denotes a PR that doesnt merit a release note. label Sep 15, 2023
@tekton-robot tekton-robot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Sep 15, 2023
@khrm
Copy link
Contributor Author

khrm commented Sep 15, 2023

/kind bug

@tekton-robot tekton-robot added the kind/bug Categorizes issue or PR as related to a bug. label Sep 15, 2023
@@ -8,4 +8,6 @@ spec:
- name: gitrevision
value: $(body.changes[0].ref.displayId)
- name: gitrepositoryurl
value: $(body.repository.links.clone[0].href)
value: $(body.pullRequest.fromRef.repository.links.clone[?(@.name=="ssh")].href)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have any reference payload data where i can look this syntax

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the operator, this is correct except for the part about handling ssh and https.

Copy link

@af-wieda af-wieda Sep 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previous expression is for a push-event payload, the new one is for pullreq-event payload.

For push event the json path is:

'$(body.repository.links.clone[?(@.name=="ssh")].href)'

Atlassian payload documentation is inconclusive, here's an example of pullrequest event payload with values edited:

{
	"eventKey": "pr:merged",
	"date": "2023-01-01T14:46:51+0000",
	"actor": {
		"name": "myuser",
		"emailAddress": "user.name@example.com",
		"id": 1,
		"displayName": "User Name",
		"active": true,
		"slug": "myuser",
		"type": "NORMAL",
		"links": {
			"self": [{
				"href": "https://bitbucket.example.com/users/myuser"
			}]
		}
	},
	"pullRequest": {
		"id": 1,
		"version": 2,
		"title": "readme.md edited online with Bitbucket",
		"state": "MERGED",
		"open": false,
		"closed": true,
		"createdDate": 1693572405591,
		"updatedDate": 1693572410874,
		"closedDate": 1693572410874,
		"fromRef": {
			"id": "refs/heads/myuser/readmemd-1693572398245",
			"displayId": "myuser/readmemd-1693572398245",
			"latestCommit": "<commit-id>",
			"type": "BRANCH",
			"repository": {
				"slug": "myreposlug",
				"id": 1234,
				"name": "myrepo",
				"description": "My repo",
				"hierarchyId": "<hiearchyId>",
				"scmId": "git",
				"state": "AVAILABLE",
				"statusMessage": "Available",
				"forkable": true,
				"project": {
					"key": "~MYUSER",
					"id": 123,
					"name": "User Name",
					"type": "PERSONAL",
					"owner": {
						"name": "username",
						"emailAddress": "user.name@example.com",
						"id": 1234,
						"displayName": "User Name",
						"active": true,
						"slug": "myuser",
						"type": "NORMAL",
						"links": {
							"self": [{
								"href": "https://bitbucket.example.com/users/myuser"
							}]
						}
					},
					"links": {
						"self": [{
							"href": "https://bitbucket.example.com/users/myuser"
						}]
					}
				},
				"public": false,
				"links": {
					"clone": [{
						"href": "https://bitbucket.example.com/scm/myprojec/myrepo.git",
						"name": "http"
					}, {
						"href": "ssh://git@bitbucket.example.com:8123/~myuser/myrepo.git",
						"name": "ssh"
					}],
					"self": [{
						"href": "https://bitbucket.example.com/users/myuser/repos/myrepo/browse"
					}]
				}
			}
		},
		"toRef": {
			"id": "refs/heads/main",
			"displayId": "main",
			"latestCommit": "<commitid>",
			"type": "BRANCH",
			"repository": {
				"slug": "myrepo",
				"id": 1234,
				"name": "myrepo",
				"description": "Repo description",
				"hierarchyId": "<hiearchy id>",
				"scmId": "git",
				"state": "AVAILABLE",
				"statusMessage": "Available",
				"forkable": true,
				"project": {
					"key": "~MYUSER",
					"id": 123,
					"name": "User Name",
					"type": "PERSONAL",
					"owner": {
						"name": "username",
						"emailAddress": "user.name@example.com",
						"id": 123,
						"displayName": "User Name",
						"active": true,
						"slug": "myuser",
						"type": "NORMAL",
						"links": {
							"self": [{
								"href": "https://bitbucket.example.com/users/myuser"
							}]
						}
					},
					"links": {
						"self": [{
							"href": "https://bitbucket.example.com/users/myuser"
						}]
					}
				},
				"public": false,
				"links": {
					"clone": [{
						"href": "https://bitbucket.example.com/scm/myrepo/myrepo.git",
						"name": "http"
					}, {
						"href": "ssh://git@bitbucket.example.com:8123/~myuser/myrepo.git",
						"name": "ssh"
					}],
					"self": [{
						"href": "https://bitbucket.example.com/users/myuser/repos/myrepo/browse"
					}]
				}
			}
		},
		"locked": false,
		"author": {
			"user": {
				"name": "myuser",
				"emailAddress": "user.name@example.com",
				"id": 1234,
				"displayName": "User Name",
				"active": true,
				"slug": "username",
				"type": "NORMAL",
				"links": {
					"self": [{
						"href": "https://bitbucket.example.com/users/myuser"
					}]
				}
			},
			"role": "AUTHOR",
			"approved": false,
			"status": "UNAPPROVED"
		},
		"reviewers": [],
		"participants": [],
		"properties": {
			"mergeCommit": {
				"displayId": "<displayid>",
				"id": "<commitid>"
			}
		},
		"links": {
			"self": [{
				"href": "https://bitbucket.example.com/users/myuser/repos/myrepo/pull-requests/1"
			}]
		}
	}
}

Copy link

@af-wieda af-wieda Sep 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's a sample payload for a push event (refs_changed):

{
	"eventKey": "repo:refs_changed",
	"date": "2023-03-30T10:30:29+0200",
	"actor": {
		"name": "user",
		"emailAddress": "user.name@example.com",
		"id": 1234,
		"displayName": "User Name",
		"active": true,
		"slug": "user",
		"type": "NORMAL",
		"links": {
			"self": [{
				"href": ["https://bitbucket.example.com/mains/user"]
			}]
		}
	},
	"repository": {
		"slug": "myrepo",
		"id": 1234,
		"name": "myrepo",
		"description": "Repo description",
		"hierarchyId": "<hiearchy id>",
		"scmId": "git",
		"state": "AVAILABLE",
		"statusMessage": "Available",
		"forkable": true,
		"project": {
			"key": "myproject",
			"id": 287,
			"name": "My Project",
			"description": "Project description",
			"public": false,
			"type": "NORMAL",
			"links": {
				"self": [{
					"href": "https://bitbucket.example.com/projects/myproject"
				}]
			}
		},
		"public": false,
		"links": {
			"clone": [{
				"href": "https://bitbucket.example.com/scm/myproject/myrepo.git",
				"name": "http"
			}, {
				"href": "ssh://git@bitbucket.example.com:8123/myproject/myrepo.git",
				"name": "ssh"
			}],
			"self": [{
				"href": "https://bitbucket.example.com/projects/myproject/repos/myrepo/browse"
			}]
		}
	},
	"changes": [{
		"ref": {
			"id": "refs/heads/master",
			"displayId": "master",
			"type": "BRANCH"
		},
		"refId": "refs/heads/master",
		"fromHash": "<commithash>",
		"toHash": "<commithash>",
		"type": "UPDATE"
	}]
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have fixed the formatting.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have fixed it for refs/push now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previous expression is for a push-event payload, the new one is for pullreq-event payload.

For push event the json path is:

'$(body.repository.links.clone[?(@.name=="ssh")].href)'

Atlassian payload documentation is inconclusive, here's an example of pullrequest event payload with values edited:

{
	"eventKey": "pr:merged",
	"date": "2023-01-01T14:46:51+0000",
	"actor": {
		"name": "myuser",
		"emailAddress": "user.name@example.com",
		"id": 1,
		"displayName": "User Name",
		"active": true,
		"slug": "myuser",
		"type": "NORMAL",
		"links": {
			"self": [{
				"href": "https://bitbucket.example.com/users/myuser"
			}]
		}
	},
	"pullRequest": {
		"id": 1,
		"version": 2,
		"title": "readme.md edited online with Bitbucket",
		"state": "MERGED",
		"open": false,
		"closed": true,
		"createdDate": 1693572405591,
		"updatedDate": 1693572410874,
		"closedDate": 1693572410874,
		"fromRef": {
			"id": "refs/heads/myuser/readmemd-1693572398245",
			"displayId": "myuser/readmemd-1693572398245",
			"latestCommit": "<commit-id>",
			"type": "BRANCH",
			"repository": {
				"slug": "myreposlug",
				"id": 1234,
				"name": "myrepo",
				"description": "My repo",
				"hierarchyId": "<hiearchyId>",
				"scmId": "git",
				"state": "AVAILABLE",
				"statusMessage": "Available",
				"forkable": true,
				"project": {
					"key": "~MYUSER",
					"id": 123,
					"name": "User Name",
					"type": "PERSONAL",
					"owner": {
						"name": "username",
						"emailAddress": "user.name@example.com",
						"id": 1234,
						"displayName": "User Name",
						"active": true,
						"slug": "myuser",
						"type": "NORMAL",
						"links": {
							"self": [{
								"href": "https://bitbucket.example.com/users/myuser"
							}]
						}
					},
					"links": {
						"self": [{
							"href": "https://bitbucket.example.com/users/myuser"
						}]
					}
				},
				"public": false,
				"links": {
					"clone": [{
						"href": "https://bitbucket.example.com/scm/myprojec/myrepo.git",
						"name": "http"
					}, {
						"href": "ssh://git@bitbucket.example.com:8123/~myuser/myrepo.git",
						"name": "ssh"
					}],
					"self": [{
						"href": "https://bitbucket.example.com/users/myuser/repos/myrepo/browse"
					}]
				}
			}
		},
		"toRef": {
			"id": "refs/heads/main",
			"displayId": "main",
			"latestCommit": "<commitid>",
			"type": "BRANCH",
			"repository": {
				"slug": "myrepo",
				"id": 1234,
				"name": "myrepo",
				"description": "Repo description",
				"hierarchyId": "<hiearchy id>",
				"scmId": "git",
				"state": "AVAILABLE",
				"statusMessage": "Available",
				"forkable": true,
				"project": {
					"key": "~MYUSER",
					"id": 123,
					"name": "User Name",
					"type": "PERSONAL",
					"owner": {
						"name": "username",
						"emailAddress": "user.name@example.com",
						"id": 123,
						"displayName": "User Name",
						"active": true,
						"slug": "myuser",
						"type": "NORMAL",
						"links": {
							"self": [{
								"href": "https://bitbucket.example.com/users/myuser"
							}]
						}
					},
					"links": {
						"self": [{
							"href": "https://bitbucket.example.com/users/myuser"
						}]
					}
				},
				"public": false,
				"links": {
					"clone": [{
						"href": "https://bitbucket.example.com/scm/myrepo/myrepo.git",
						"name": "http"
					}, {
						"href": "ssh://git@bitbucket.example.com:8123/~myuser/myrepo.git",
						"name": "ssh"
					}],
					"self": [{
						"href": "https://bitbucket.example.com/users/myuser/repos/myrepo/browse"
					}]
				}
			}
		},
		"locked": false,
		"author": {
			"user": {
				"name": "myuser",
				"emailAddress": "user.name@example.com",
				"id": 1234,
				"displayName": "User Name",
				"active": true,
				"slug": "username",
				"type": "NORMAL",
				"links": {
					"self": [{
						"href": "https://bitbucket.example.com/users/myuser"
					}]
				}
			},
			"role": "AUTHOR",
			"approved": false,
			"status": "UNAPPROVED"
		},
		"reviewers": [],
		"participants": [],
		"properties": {
			"mergeCommit": {
				"displayId": "<displayid>",
				"id": "<commitid>"
			}
		},
		"links": {
			"self": [{
				"href": "https://bitbucket.example.com/users/myuser/repos/myrepo/pull-requests/1"
			}]
		}
	}
}

Thank you @af-wieda 👍

@khrm
Copy link
Contributor Author

khrm commented Sep 15, 2023

/retest

Build tests shouldn't fail. The integration test failing is correct.

Fix the bitbucket server example when it has both SSH and HTTPS.
@khrm
Copy link
Contributor Author

khrm commented Sep 15, 2023

/retest

@savitaashture
Copy link
Contributor

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Sep 15, 2023
@dibyom
Copy link
Member

dibyom commented Sep 20, 2023

fixes #1640

@savitaashture savitaashture added this to the Triggers v0.26 milestone Sep 20, 2023
@dibyom
Copy link
Member

dibyom commented Sep 20, 2023

/approve

@tekton-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dibyom

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@tekton-robot tekton-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 20, 2023
@tekton-robot tekton-robot merged commit fad25af into main Sep 20, 2023
6 checks passed
@khrm khrm deleted the khrm-patch-1 branch September 26, 2023 05:27
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/bug Categorizes issue or PR as related to a bug. lgtm Indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesnt merit a release note. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants