Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
ShreyamMaity committed Nov 15, 2021
1 parent 418f16e commit c806333
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 8 deletions.
129 changes: 127 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,127 @@
# Assignmenty
Just Code and Push , Leave The Assignment Part on us....
<h1 align="center">Assignmenty Bot</h1>

</p>

<p align="center">
<img src="https://img.shields.io/badge/language-python-blue?style"/>
<img src="https://img.shields.io/github/license/ShreyamMaity/Assignmenty"/>
<img src="https://img.shields.io/github/stars/ShreyamMaity/Assignmenty"/>
<img src="https://img.shields.io/github/forks/ShreyamMaity/Assignmenty"/>
<img src="https://img.shields.io/static/v1?label=%F0%9F%8C%9F&message=If%20Useful&style=style=flat&color=BC4E99" alt="Star Badge"/>
<img src=https://visitor-badge.glitch.me/badge?page_id=ShreyamMaity.Assignmenty"/>
</p>

----

> Just Code and Push , Leave The Assignment Part on us....Happy Coding </>


- This is a [GitHub Action](https://developer.github.com/actions/) to create your assignment automatically with help of version control.

- It takes code and snaps from your latest commit and make it an assignment and send you in mail📧

- This action runs in a Docker container and therefore only supports Linux🐧
-----
## Prep Work

1. Create you coding assignments like
```bash
``` This is Your Question , Write Questions like this```

def code():
this is your code. Just code anything

```
2. Save the code file as `assignment12.py` or `assignment34.py`
> This action currently supports only **Python Code Assignments** 🐍<br/>
> but this GitHub Action can me modified for any code based asssignments.Feel free to contribute.🤗
- You can use [this](#usage) example to work it out 🧐
3. create a github repo and clone it, then add a action config (`.yml`) file.Steps are avialable[here](#action-config-guide) for more info 🤔
4. Add a template docx file and name it `tmplate.docx` or use my template and modify it. Check the template [here](./content/templat.docx) 📑
5. save the template file , action config file in your github repo 🐙
6. Push your code with snaps and Enjoy 😍


-----

## Usage :

The following example [workflow step](https://help.github.com/en/actions/configuring-and-managing-workflows/configuring-a-workflow) will get your latest commit and take the code file and snaps to form a `.docx` based assignment and send you via mail.

- ```yml
name: Assignmenty Mailer
on:
push:
branches:
- main
workflow_dispatch:
jobs:
mailer:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 2
- uses: ShreyamMaity/Assignmenty@main
with:
MAILID : '[email protected]' #mail if of your choice
FILENAME : 'assignment' #assignment file name
```
Just copy the above code and paste it in your `.yml` file

----


## Options ⚙️

The following input variable options can/must be configured:

|Input variable|Necessity|Description|
|--------------------|--------|-----------|
|`MAILID`|Required|your mail id where you want to recieve the assignment|
|`FILENAME`|Required|your assignment file name|

----
## Action Config Guide

- ## Dir Methord :
- Create a `.github/workflows` directory in your repository on GitHub if this directory does not already exist.
- In the `.github/workflows` directory, create a file named `mailer.yml`.
- open the `mailer.yml` file and paste this code :
```yml
name: Assignmenty Mailer
on:
push:
branches:
- main
workflow_dispatch:
jobs:
mailer:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 2
- uses: ShreyamMaity/Assignmenty@main
with:
MAILID : '[email protected]' #mail if of your choice
FILENAME : 'assignment' #assignment file name
```
- ## UI Methord :
- go to the `Actions` tab in your github repository
- press `set up a workflow yourself`
- Delete the base code and paste above code
- start commit
- and all set
-----
## Author

The Copy Paste GitHub action is written by [Shreyam Maity](https://github.com/ShreyamMaity)

-----

## License

This project is licensed under the [MIT License](https://opensource.org/licenses/MIT) - see the [LICENSE](LICENSE) file for details.

File renamed without changes.
22 changes: 16 additions & 6 deletions script.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,15 @@ def mailSender(assignment, subject, body, mail):
message = service.users().messages().send(userId='me', body={'raw': raw_string}).execute()
print('Message Id: %s' % message['id'])

def getCommitFiles():
files = subprocess.check_output(['git', 'diff-tree', '--no-commit-id', '--name-only', '-r', 'HEAD']).decode('utf-8').split('\n')

def getLastCommit():
return subprocess.check_output(['git', 'rev-parse', 'HEAD']).decode('utf-8').strip()


def getCommitFiles(commitID):
files = subprocess.check_output(['git', 'show', '--pretty=', '--name-only' , str(commitID)]).decode('utf-8').split('\n')
print('Last Commit : \n')
print(files)
return files

def getPyFiles(fileList):
Expand All @@ -78,6 +85,9 @@ def getPyFiles(fileList):
sort[m.group()] = file
for k, v in sorted(sort.items(), key=lambda x: int(x[0])):
pyFiles.append(v)

print('Got Pyfiles : \n')
print(pyFiles)
return pyFiles

def getQuestions(fileList):
Expand Down Expand Up @@ -159,21 +169,21 @@ def removeFiles(pdfName):
os.remove(pdfName + '.docx')
for file in glob.glob("*.png"):
os.remove(file)

def main():

mailId = os.environ['INPUT_MAILID']
fileName = os.environ['INPUT_FILENAME']
fileList = getCommitFiles()
fileList = getCommitFiles(getLastCommit())
pyFiles = getPyFiles(fileList)
questions = getQuestions(pyFiles)
snaps = getRunSnaps(fileList)
buildPdf(pyFiles, questions, snaps, 'template.docx' , fileName)
mailSender(fileName, 'Your Assignment Is here', 'Hello User, Thanks for using Assignment Bot. Hope You love our sevice 😊\n', mailId)
removeFiles(fileName)




if __name__ == '__main__':
main()
main()

0 comments on commit c806333

Please sign in to comment.