I am trying to trigger some actions based on label of pull request.
I am not sure how to retrieve the details of the label
Here is a simplified action to illustrate and I expect that all these will show me some info about the labels but all i got is “1” in the output.
A little more info: I checked on Frequently Asked Questions of Gitea Actions | Gitea Documentation and it listed labeled as one of the actions that is supported and compatible with github. The same actions work on github. (but with the variables being github.xx instead of gitea.xx of course )
${{ gitea.event.label.name }}
just isn’t enough to get the data you want. You actually need to use the following.
${{ gitea.event.pull_request.labels[0].name }}
So, you first need to access the pull_request object where you will find the labels array. With the code above you just get the first label. I don’t know if there’s a simple way to just iterate over all labels in case there’s more than one.
I guess to better understand you can have a look at Github - Webhook events and payloads.
I was running into the same problem and looking for a more elegant solution, and what I figured out after dumping ${{ gitea }}’s JSON content is as follows:
Gitea is secretly converting github action events into its own implementation, and converts types: [labeled] and [unlabeled] to a label_updated action with a different webhook payload structure:
This event triggers both when adding or removing (disregarding types:[labeled] or [unlabeled]), and will run separately for each label, even when adding/removing multiple labels in a single user action.
In conclusion:
In gitea instead of ${{ gitea.event.label.name }} you have to use ${{gitea.event.changes.added_labels[0].name }} or ${{gitea.event.changes.removed_labels[0].name }} (in case of trying to imitate a types: [unlabel] action)