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

Commit

Permalink
Merge pull request #3 from udda1996/sync-action-bbe
Browse files Browse the repository at this point in the history
Sync action bbe with dev website
  • Loading branch information
praneesha authored Sep 2, 2022
2 parents bd518b3 + 3057c7a commit 6dbc930
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 34 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/update_dev_website.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ jobs:

- name: Install Python Packages
run: |
pip install beautifulsoup4
pip install PyGithub
- name: Update Ballerina Dev Website
run: python3 src/scripts/update_html.py
run: python3 src/scripts/update_dev_website.py
env:
BALLERINA_BOT_USERNAME: ${{ secrets.BALLERINA_BOT_USERNAME }}
BALLERINA_BOT_TOKEN: ${{ secrets.BALLERINA_BOT_TOKEN }}
Expand Down
44 changes: 12 additions & 32 deletions src/scripts/update_html.py → src/scripts/update_dev_website.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import time

from github import Github, InputGitAuthor, GithubException
from bs4 import BeautifulSoup

ballerina_bot_username = os.environ['BALLERINA_BOT_USERNAME']
ballerina_bot_token = os.environ['BALLERINA_BOT_TOKEN']
Expand All @@ -14,44 +13,25 @@
github = Github(ballerina_bot_token)

def main():
repo = github.get_repo('ballerina-platform/ballerina-dev-website', 'master')
html_file = repo.get_contents('index.html')
html_file = html_file.decoded_content.decode('utf-8')

with open('index.html', 'w') as write_obj:
write_obj.write(html_file)

with open('index.html','r') as soup1:
html_doc = soup1.read()
soup = BeautifulSoup(html_doc, 'html.parser')

with open('src/scripts/working_with_data.bal', 'r') as action_obj:
action_bbe = action_obj.readlines()

old_text = soup.find('div', {'id':'working-with-data'})

with open('index.html','r') as read_obj:
html_doc_lines = read_obj.readlines()

with open('edited_index.html', 'a') as new_html:
for line in html_doc_lines[0:old_text.code.sourceline]:
new_html.write(line)
for line in action_bbe[0:len(action_bbe)]:
new_html.write(line)
new_html.write("\n")
for line in html_doc_lines[old_text.code.sourceline+len(old_text.code.string.strip().splitlines()):len(html_doc_lines)]:
new_html.write(line)

with open('edited_index.html', 'r') as commit_obj:
updated_bal_file = action_obj.read()
with open('working-with-data.md', 'a') as write_obj:
write_obj.write("```\n")
write_obj.write(updated_bal_file + "\n")
write_obj.write("```")
write_obj.close()
action_obj.close()

with open('working-with-data.md','r') as commit_obj:
updated_file = commit_obj.read()

commit_message = 'Update Ballerina in Action samples'
try:
update = commit_file('index.html', updated_file, 'update-working-with-data', commit_message)[0]
update = commit_file('components/home-page/bal-action/working-with-data.md', updated_file, 'update-working-with-data', commit_message)[0]

if update:
pr_title = '[Automated] Update Ballerina in Action samples'
pr_body = 'Update Ballerina in Action samples for source code changes in working with data'
pr_body = 'Update Ballerina in Action samples for source code changes in `Working with data`'
head_branch = 'update-working-with-data'
open_pull_request(pr_title, pr_body, head_branch)

Expand Down

0 comments on commit 6dbc930

Please sign in to comment.