From 47cf9ce598cafe33e223e73693e5adf251da8aff Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Mon, 28 Sep 2020 17:44:17 -0700 Subject: [PATCH] Misc --- .github/workflows/assignIssue.yml | 123 ++++++++++++++++++++++++++++++ .github/workflows/week.js | 29 +++++++ 2 files changed, 152 insertions(+) create mode 100644 .github/workflows/assignIssue.yml create mode 100644 .github/workflows/week.js diff --git a/.github/workflows/assignIssue.yml b/.github/workflows/assignIssue.yml new file mode 100644 index 000000000000..c933d4173f21 --- /dev/null +++ b/.github/workflows/assignIssue.yml @@ -0,0 +1,123 @@ +name: Assign DS issue to someone +on: + issues: + types: [opened] +jobs: + assignIssue: + name: Assign Issue to Someone + runs-on: ubuntu-latest + if: github.repository == 'microsoft/vscode-python' + steps: + - name: Created internally + id: internal + env: + ISSUE_OWNER: ${{github.event.issue.owner.login}} + run: | + echo ::set-output name=result::$(node -p -e "['rchiodo', 'greazer', 'joyceerhl', 'DavidKutu', 'claudiaregio', 'IanMatthewHuff', 'DonJayamanne'].filter(item => process.env.ISSUE_OWNER.toLowerCase() === item.toLowerCase()).length > 0 ? 1 : 0") + shell: bash + - name: Should we proceed + id: proceed + env: + ISSUE_LABELS: ${{toJson(github.event.issue.labels)}} + ISSUE_ASSIGNEES: ${{toJson(github.event.issue.assignees)}} + ISSUE_IS_INTERNAL: ${{steps.internal.outputs.result}} + run: | + echo ::set-output name=result::$(node -p -e "process.env.ISSUE_IS_INTERNAL === '0' && JSON.parse(process.env.ISSUE_ASSIGNEES).length === 0 && JSON.parse(process.env.ISSUE_LABELS).filter(item => item.name.indexOf('data science') >= 0).length === 0 ? 1 : 0") + shell: bash + - uses: actions/checkout@v2 + if: steps.proceed.outputs.result == 1 + - name: Day of week + if: steps.proceed.outputs.result == 1 + id: day + run: | + echo ::set-output name=number::$(node -p -e "new Date().getDay()") + shell: bash + - name: Hour of day + if: steps.proceed.outputs.result == 1 + id: hour + run: | + echo ::set-output name=hour::$(node -p -e "(new Date().getUTCHours() - 7)%24") + shell: bash + - name: Week Number + if: steps.proceed.outputs.result == 1 + id: week + run: | + echo ::set-output name=odd::$(node .github/workflows/week.js) + shell: bash + - name: Print day and week + if: steps.proceed.outputs.result == 1 + run: | + echo ${{steps.day.outputs.number}} + echo ${{steps.week.outputs.odd}} + echo ${{steps.hour.outputs.hour}} + shell: bash + - name: Even late friday (David) + if: steps.proceed.outputs.result == 1 && steps.week.outputs.odd == 0 && steps.day.outputs.number == 5 && steps.hour.outputs.hour >= 16 + uses: actions/github@v1.0.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + args: assign DavidKutu + - name: Odd late friday (Joyce) + if: steps.proceed.outputs.result == 1 && steps.week.outputs.odd == 1 && steps.day.outputs.number == 5 && steps.hour.outputs.hour >= 16 + uses: actions/github@v1.0.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + args: assign joyceerhl + - name: Odd weekends (David) + if: steps.proceed.outputs.result == 1 && steps.week.outputs.odd == 1 && (steps.day.outputs.number == 6 || steps.day.outputs.number == 0) + uses: actions/github@v1.0.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + args: assign DavidKutu + - name: Even weekends (Joyce) + if: steps.proceed.outputs.result == 1 && steps.week.outputs.odd == 0 && (steps.day.outputs.number == 6 || steps.day.outputs.number == 0) + uses: actions/github@v1.0.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + args: assign joyceerhl + - name: Odd Monday (David) + if: steps.proceed.outputs.result == 1 && steps.week.outputs.odd == 1 && steps.day.outputs.number == 1 && steps.hour.outputs.hour < 16 + uses: actions/github@v1.0.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + args: assign DavidKutu + - name: Even Monday (Joyce) + if: steps.proceed.outputs.result == 1 && steps.week.outputs.odd == 0 && steps.day.outputs.number == 1 && steps.hour.outputs.hour < 16 + uses: actions/github@v1.0.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + args: assign joyceerhl + - name: Tuesday (Ian) + if: steps.proceed.outputs.result == 1 && (steps.day.outputs.number == 1 && steps.hour.outputs.hour >= 16) || (steps.day.outputs.number == 2 && steps.hour.outputs.hour < 16) + uses: actions/github@v1.0.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + args: assign IanMatthewHuff + - name: Wednesday (Rich) + if: steps.proceed.outputs.result == 1 && (steps.day.outputs.number == 2 && steps.hour.outputs.hour >= 16) || (steps.day.outputs.number == 3 && steps.hour.outputs.hour < 16) + uses: actions/github@v1.0.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + args: assign rchiodo + - name: Thursday (Don) + if: steps.proceed.outputs.result == 1 && (steps.day.outputs.number == 3 && steps.hour.outputs.hour >= 16) || (steps.day.outputs.number == 4 && steps.hour.outputs.hour < 16) + uses: actions/github@v1.0.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + args: assign DonJayamanne + - name: Friday (Claudia) + if: steps.proceed.outputs.result == 1 && (steps.day.outputs.number == 4 && steps.hour.outputs.hour >= 16) || (steps.day.outputs.number == 5 && steps.hour.outputs.hour < 16) + uses: actions/github@v1.0.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + args: assign claudiaregio diff --git a/.github/workflows/week.js b/.github/workflows/week.js new file mode 100644 index 000000000000..b8a11013283b --- /dev/null +++ b/.github/workflows/week.js @@ -0,0 +1,29 @@ +/* For a given date, get the ISO week number + * + * Based on information at: + * + * http://www.merlyn.demon.co.uk/weekcalc.htm#WNR + * + * Algorithm is to find nearest thursday, it's year + * is the year of the week number. Then get weeks + * between that date and the first day of that year. + * + * Note that dates in one year can be weeks of previous + * or next year, overlap is up to 3 days. + * + * e.g. 2014/12/29 is Monday in week 1 of 2015 + * 2012/1/1 is Sunday in week 52 of 2011 + */ +function getWeekNumber(d) { + // Copy date so don't modify original + d = new Date(Date.UTC(d.getFullYear(), d.getMonth(), d.getDate())); + // Set to nearest Thursday: current date + 4 - current day number + // Make Sunday's day number 7 + d.setUTCDate(d.getUTCDate() + 4 - (d.getUTCDay() || 7)); + // Get first day of year + var yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1)); + // Calculate full weeks to nearest Thursday + return Math.ceil(((d - yearStart) / 86400000 + 1) / 7); +} +// Whether it is an odd or event week. +console.log(getWeekNumber(new Date()) % 2);