Skip to content
This repository has been archived by the owner on Aug 30, 2023. It is now read-only.

Commit

Permalink
feat: too many changes to explain
Browse files Browse the repository at this point in the history
- consuming this action successfully
- turns out I have to use node? rewriting all the things
  • Loading branch information
Shesekino committed Mar 15, 2020
1 parent eda59c0 commit 0fb4714
Show file tree
Hide file tree
Showing 9 changed files with 152 additions and 62 deletions.
13 changes: 0 additions & 13 deletions .github/workflows/consistency.yaml

This file was deleted.

18 changes: 6 additions & 12 deletions .github/workflows/release-notes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,18 @@ on:
jobs:
preview:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8]
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- run: |
git fetch --prune --unshallow --tags
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
# TODO: cache node_modules
- run: |
npm i
- uses: ./
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install requests
- name: Post release notes
run: python $GITHUB_WORKSPACE/py/main.py
releaseBranch: master
githubPosterId: 18642669
env:
GITHUB_USERNAME: ${{ github.actor }}
GITHUB_TOKEN: ${{ secrets.RELEASE_NOTES_PREVIEW_GITHUB_TOKEN }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist
node_modules
6 changes: 0 additions & 6 deletions .releaserc

This file was deleted.

40 changes: 13 additions & 27 deletions action.yaml
Original file line number Diff line number Diff line change
@@ -1,30 +1,16 @@
name: Release-Notes-Preview
author: 'Amir Moualem'
description: 'Presents a preview of expected release notes should the PR get merged, based on Semantic Release.'

on:
pull_request:
branches: [ master ]
inputs:
releaseBranch:
description: 'Branch where the Semantic Release will occur.'
required: false
default: 'master'
githubPosterId:
description: 'ID of the user associated with the GITHUB_TOKEN. Used to delete previous release notes previews so we dont spam pull requests.'
required: true

jobs:
preview:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8]
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- run: |
git fetch --prune --unshallow --tags
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install requests
- name: Post release notes
run: python $GITHUB_WORKSPACE/py/main.py
env:
GITHUB_USERNAME: ${{ github.actor }}
GITHUB_TOKEN: ${{ secrets.RELEASE_NOTES_PREVIEW_GITHUB_TOKEN }}
runs:
using: node12
main: dist/index.js
36 changes: 36 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const fs = require('fs');
const needle = require('needle');

const GITHUB_TOKEN = process.env.GITHUB_TOKEN;

const eventName = process.env.GITHUB_EVENT_NAME;
if (eventName !== 'pull_request') {
process.exit(1);
}

const eventPath = process.env.GITHUB_EVENT_PATH;
const eventData = fs.readFileSync(eventPath);
const event = JSON.parse(eventData);
console.log(event);

const issueUrl = event.pull_request.issue_url;

const url = `${issueUrl}/comments`;
const payload = {
body: 'There\'s butter on my face!',
};
const options = {
json: true,
compressed: true,
headers: {
Authorization: 'token ' + GITHUB_TOKEN,
},
};


needle('post', url, payload, options)
.then((response) => {
console.log('huzzah!');
}).catch((err) => {
console.log('I have no idea what I\'m doing');
});
48 changes: 48 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "release-notes-preview",
"description": "Presents a preview of expected release notes should the PR get merged, based on Semantic Release.",
"license": "MIT",
"main": "dist/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/snyk/release-notes-preview.git"
},
"author": "Amir Moualem",
"bugs": {
"url": "https://github.com/snyk/release-notes-preview/issues"
},
"homepage": "https://github.com/snyk/release-notes-preview#readme",
"dependencies": {
"needle": "^2.3.3"
},
"release": {
"branches": "master",
"verifyConditions": [
"@semantic-release/github"
],
"publish": [
"@semantic-release/github"
],
"success": [
"@semantic-release/github"
],
"fail": [
"@semantic-release/github"
]
}
}
15 changes: 11 additions & 4 deletions py/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@
if eventName != 'pull_request':
sys.exit(0)

RELEASE_BRANCH = os.environ['INPUT_RELEASE_BRANCH']
if not RELEASE_BRANCH:
print('INPUT_RELEASE_BRANCH is missing')
sys.exit(1)
GITHUB_POSTER_ID = os.environ['INPUT_GITHUB_POSTER_ID']
if not GITHUB_POSTER_ID:
print('INPUT_GITHUB_POSTER_ID is missing')
sys.exit(1)
GITHUB_USERNAME = os.environ.get('GITHUB_USERNAME', 'USER_NOT_FOUND')
GITHUB_OWNER_AND_REPO = os.environ['GITHUB_REPOSITORY']
GITHUB_TOKEN = os.environ['GITHUB_TOKEN']
Expand Down Expand Up @@ -45,8 +53,7 @@ def main():
# TODO replace login & id for the details of the token
commentIds = [
comment['id'] for comment in allCommentsResponse
if comment['user']['login'] == 'snyk-deployer'
and comment['user']['id'] == 18642669
if comment['user']['id'] == 18642669
and 'Expected release notes' in comment['body']
]

Expand All @@ -57,8 +64,8 @@ def main():
headers=headers,
)

# TODO: "master" needs to be parameterised
lastVersion = subprocess.check_output(['git', 'describe', '--abbrev=0', '--tags', 'origin/master'], text=True, stderr=subprocess.STDOUT).strip()
releaseBranchString = 'origin/%s' % RELEASE_BRANCH
lastVersion = subprocess.check_output(['git', 'describe', '--abbrev=0', '--tags', releaseBranchString], text=True, stderr=subprocess.STDOUT).strip()
commitsSinceLastVersion = subprocess.check_output(['git', 'log', '--no-decorate', lastVersion + '..HEAD', '--oneline'], text=True).strip()
commits = processCommits(commitsSinceLastVersion)
if not (commits['features'] or commits['fixes']):
Expand Down

0 comments on commit 0fb4714

Please sign in to comment.