How can I clean/delete a Jenkins workspace after merge? I would like to keep a workspace in Jenkins until after the pull request is merged. Meaning, I don't want to clear the workspace after every build, but I also don't want to clear the workspace only when the branch gets deleted.

How can I use the github webhooks to trigger a workspace cleanup whenever a pull request gets resolved as merged?

Ideally, the solution would involve using my JenkinsFile/Pipelines.

edit: Background.

We have long-lived branches and short-lived branches. For brevity, I'll call the long-lived branches "team branches".  Our workflow is to take short-lived branches, such as feature branches and make a PR request to pull them into the team branches.

On Jenkins, we then build the feature branch and the PR request and the team branch.  Normally this works fine, but sometimes when multiple teams are merging to qa each team and feature branch needs to update(pull) and then get built on Jenkins again.  Currently, we are always cleaning the workspace which makes the update builds take longer than they need to. So I want to be able to preserve the workspace until all updates are done and the PR request actually gets merged, only then do I want to delete the workspace for the feature branch and the PR request and the team branch.
I am assuming you are using Jenkinsfile. You can do for example:

pipeline {
    agent any

    stages {
        stage('Build') {
            steps {
                echo 'Building..'
            }
        }
        stage('Test') {
            steps {
                echo 'Testing..'
            }
        }
        stage('Deploy') {
             when { branch 'master' } /* when in master branch */
             steps {
                echo 'Deploying....'
                deleteDir() /* clean up our workspace */
            }
        }
    }
}