diff --git a/.gitignore b/.gitignore index 5f3bb6d..4e1703b 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ contributors.yml packages.yml all_contribs.pickle all_contribs_dict.pickle +token.txt .vscode/ .token __pycache__ diff --git a/README.md b/README.md index db3c67b..301b5d0 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/import-token.py b/import-token.py deleted file mode 100644 index f6940d4..0000000 --- a/import-token.py +++ /dev/null @@ -1,19 +0,0 @@ -# TODO: This will become automated in a CI workflow -import pickle - -with open("../token.pickle", "rb") as f: - API_TOKEN = pickle.load(f) - -with open("../token.pickle", "wb") as f: - pickle.dump(API_TOKEN, f) - - -with open("../issues.pickle", "rb") as f: - API_TOKEN = pickle.load(f) - -with open("../issues.pickle", "wb") as f: - pickle.dump(issues, f) - -final_contribs = all_contribs_dict_up -with open("all_contribs.pickle", "wb") as f: - pickle.dump(all_contribs_dict_up, f) diff --git a/parse-contributors.py b/parse-contributors.py index ac5c646..e391d4a 100644 --- a/parse-contributors.py +++ b/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", diff --git a/parse_review_issues.py b/parse_review_issues.py index 0a48005..5fcc5ca 100644 --- a/parse_review_issues.py +++ b/parse_review_issues.py @@ -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 diff --git a/src/pyosmeta/file_io.py b/src/pyosmeta/file_io.py index b3cd836..718f255 100644 --- a/src/pyosmeta/file_io.py +++ b/src/pyosmeta/file_io.py @@ -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: """ diff --git a/update_reviewers.py b/update_reviewers.py index 8d2004f..fcd870c 100644 --- a/update_reviewers.py +++ b/update_reviewers.py @@ -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: