Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/actions/get-workflow-origin
Submodule get-workflow-origin added at 1b5a8a
44 changes: 0 additions & 44 deletions .github/workflows/document_bot.yml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,17 @@
# specific language governing permissions and limitations
# under the License.

name: "Pull Request Labeler"

name: PR-Edit-Trigger
on:
pull_request_target:
types:
- opened
pull_request:
types: [edited]
branches:
- main
- release-*

jobs:
triage:
if: (github.repository == 'apache/flink-agents')
permissions:
contents: read
pull-requests: write
issues: write
label:
runs-on: ubuntu-latest
steps:
- uses: actions/labeler@v5
- name: "Do nothing. Just triggers corresponding workflow."
run: echo
100 changes: 100 additions & 0 deletions .github/workflows/pr_labeler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

module.exports = async ({ github, context, core, prNumber, triggerWorkflow }) => {
if (!prNumber) {
core.warning('No PR number found, skipping labeling.');
return;
}

const { data: pr } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber,
});

const isOpenTrigger = triggerWorkflow === 'PR-Open-Trigger';
const labels = [];

// --- Labels only added on PR open (priority/major, fixVersion) ---

if (isOpenTrigger) {
labels.push('priority/major');

const baseBranch = pr.base.ref;
const fixVersionLabelMap = {
'main': 'fixVersion/0.3.0',
'release-0.2': 'fixVersion/0.2.1',
'release-0.1': 'fixVersion/0.1.2',
};
const fixVersionLabel = fixVersionLabelMap[baseBranch];
if (fixVersionLabel) {
labels.push(fixVersionLabel);
}
}

// --- Documentation labels (evaluated on both open and edit) ---

const docLabels = ['doc-needed', 'doc-not-needed', 'doc-included'];
const docMissingLabel = 'doc-label-missing';
const prBody = pr.body || '';
const checkedDocLabel = docLabels.find(label => {
const pattern = new RegExp(`-\\s*\\[x\\]\\s*\`${label}\``, 'i');
return pattern.test(prBody);
});

// Remove all existing doc labels first
const { data: existingLabels } = await github.rest.issues.listLabelsOnIssue({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
});
const allDocLabels = [...docLabels, docMissingLabel];
for (const existingLabel of existingLabels) {
if (allDocLabels.includes(existingLabel.name)) {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
name: existingLabel.name,
});
core.info(`Removed existing doc label '${existingLabel.name}'.`);
}
}

if (checkedDocLabel) {
labels.push(checkedDocLabel);
core.info(`Documentation checkbox checked: '${checkedDocLabel}'.`);
} else {
labels.push(docMissingLabel);
core.info('No documentation checkbox checked, adding doc-label-missing.');
}

// --- Apply all labels ---

if (labels.length > 0) {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
labels: labels,
});
core.info(`Added labels: ${labels.join(', ')}`);
} else {
core.info('No labels to add.');
}
};
58 changes: 58 additions & 0 deletions .github/workflows/pr_labeler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

name: "Pull Request Labeler"

on:
workflow_run:
workflows: [PR-Open-Trigger, PR-Edit-Trigger]
types: [requested]

concurrency:
group: ${{ github.event.workflow_run.name }}-${{ github.event.workflow_run.head_repository.full_name }}-${{ github.event.workflow_run.head_branch }}
cancel-in-progress: true

permissions:
checks: write
contents: read
pull-requests: write

jobs:
label:
if: github.repository == 'apache/flink-agents'
runs-on: ubuntu-latest
steps:
- name: "Checkout ${{ github.ref }} ( ${{ github.sha }} )"
uses: actions/checkout@v6
with:
persist-credentials: false
submodules: recursive
- name: "Get information about the original trigger of the run"
uses: ./.github/actions/get-workflow-origin
id: source-run-info
with:
token: ${{ secrets.GITHUB_TOKEN }}
sourceRunId: ${{ github.event.workflow_run.id }}
- name: "Add labels to pull request"
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const script = require('./.github/workflows/pr_labeler.js');
const prNumber = parseInt('${{ steps.source-run-info.outputs.pullRequestNumber }}');
const triggerWorkflow = '${{ github.event.workflow_run.name }}';
await script({ github, context, core, prNumber, triggerWorkflow });
28 changes: 13 additions & 15 deletions .github/labeler.yml → .github/workflows/pr_open_trigger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,17 @@
# specific language governing permissions and limitations
# under the License.

# Add 'priority/major' label to any changes within the entire repository
priority/major:
- changed-files:
- any-glob-to-any-file: '**'
name: PR-Open-Trigger
on:
pull_request:
types: [opened]
branches:
- main
- release-*

# Add 'fixVersion/0.3.0' label to any PR that is opened against the `main` branch
fixVersion/0.3.0:
- base-branch: 'main'

# Add 'fixVersion/0.2.1' label to any PR that is opened against the `release-0.2` branch
fixVersion/0.2.1:
- base-branch: 'release-0.2'

# Add 'fixVersion/0.1.1' label to any PR that is opened against the `release-0.1` branch
fixVersion/0.1.1:
- base-branch: 'release-0.1'
jobs:
label:
runs-on: ubuntu-latest
steps:
- name: "Do nothing. Just triggers corresponding workflow."
run: echo
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "docs/themes/book"]
path = docs/themes/book
url = https://github.com/alex-shpak/hugo-book
[submodule ".github/actions/get-workflow-origin"]
path = .github/actions/get-workflow-origin
url = https://github.com/potiuk/get-workflow-origin
Loading