Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move Token Import From a Pickle File Import to a Simple Text File #23

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -3,6 +3,7 @@ contributors.yml
packages.yml
all_contribs.pickle
all_contribs_dict.pickle
token.txt
.vscode/
.token
__pycache__
Expand Down
7 changes: 2 additions & 5 deletions README.md
Expand Up @@ -13,11 +13,8 @@ For an action to work will need to figure out the token part: https://github.com

To run this you need to [create a TOKEN that can be used to access the GitHub
API.](https://docs.github.com/en/rest/guides/getting-started-with-the-rest-api?apiVersion=2022-11-28#about-tokens).
Store the token as a `.pickle` object containing a single string with the
Token value within it.

TODO: it might make more sense to store the token value as .token in the github
repo and then I can add that to the gitignore?
In the root of the project directory, store the token in a file named `token.txt`,
containing a single string with the token value.

## How to run each script

Expand Down
19 changes: 0 additions & 19 deletions import-token.py

This file was deleted.

4 changes: 2 additions & 2 deletions parse-contributors.py
@@ -1,9 +1,9 @@
import pickle

from pyosmeta.contributors import ProcessContributors
from pyosmeta.file_io import read_text_file

with open("../token.pickle", "rb") as f:
API_TOKEN = pickle.load(f)
API_TOKEN = read_text_file("token.txt")

json_files = [
"https://raw.githubusercontent.com/pyOpenSci/python-package-guide/main/.all-contributorsrc",
Expand Down
6 changes: 2 additions & 4 deletions parse_review_issues.py
Expand Up @@ -11,12 +11,10 @@
"""


import pickle

from pyosmeta import ProcessIssues
from pyosmeta.file_io import read_text_file

with open("../token.pickle", "rb") as f:
API_TOKEN = pickle.load(f)
API_TOKEN = read_text_file("token.txt")

# TODO: looks like sometimes the gh username is the name then @. so i need to create
# code that looks for the @ and adds the username to ghusername and the rest to the name
Expand Down
17 changes: 17 additions & 0 deletions src/pyosmeta/file_io.py
Expand Up @@ -6,6 +6,23 @@
# file io


def read_text_file(filename: str) -> str:
"""Read a text file and return the contents as a string.

Parameters
----------
filename : str
Path to the text file to be read.

Returns
-------
str
The contents of the text file.
"""
with open(filename, "r") as f:
return f.readline()


@dataclass
class YamlIO:
"""
Expand Down
5 changes: 2 additions & 3 deletions update_reviewers.py
Expand Up @@ -21,10 +21,9 @@

from pyosmeta.contrib_review_meta import UpdateReviewMeta
from pyosmeta.contributors import ProcessContributors
from pyosmeta.file_io import YamlIO
from pyosmeta.file_io import YamlIO, read_text_file

with open("../token.pickle", "rb") as f:
API_TOKEN = pickle.load(f)
API_TOKEN = read_text_file("token.txt")

# Load contributors dict from website (just for now)
with open("all_contribs.pickle", "rb") as f:
Expand Down