From 61fcc6d165cc7d31533153b3a09d0ed837c1ee79 Mon Sep 17 00:00:00 2001 From: smiley Date: Tue, 18 Jul 2023 01:28:46 +0200 Subject: [PATCH] :octocat: --- README.md | 22 +++++++++++++++------- cli/run.php | 27 ++++++++++----------------- data/.gitkeep | 0 src/MyTootBot.php | 9 +++++---- tests/MyTootBotTest.php | 6 ++++-- 5 files changed, 34 insertions(+), 30 deletions(-) create mode 100644 data/.gitkeep diff --git a/README.md b/README.md index 1874cc53..1432262f 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ - clone this repository - create a mastodon account for your bot, e.g. on https://botsin.space/ - when your account is approved, go to the [development settings](https://botsin.space/settings/applications) and create a new application -- copy [`/config/.env_example`](./config/.env_example) to `/config/.env` +- copy [`/config/.env_example`](./config/.env_example) to `/config/.env` (for local test, **do not upload the .env to GitHub!**) - copy the access token from the mastodon application and save it in the `.env` as `MASTODON_TOKEN`, go to the repository settings on GitHub under `{repo_url}/settings/secrets/actions` and save it there too (not necessary if you plan to run the bot on your own webserver) - save the mastodon instance URL in the `.env` as `MASTODON_INSTANCE`, save it as GitHub repository secret as well - if you plan to use remote authentication with the mastodon app, you will need to do the same for the client key, secret and callback-URL @@ -69,14 +69,22 @@ jobs: # please note that this requires read/write permissions for the actions runner! - name: "Commit log" - run: | - git config user.name github-actions - git config user.email github-actions@github.com - git add data/posted.json - git commit -m "posted toot" - git push + uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: ":octocat: posted toot" + file_pattern: 'data/posted.json' ``` +## related projects +- [php-tootbot/php-tootbot](https://github.com/php-tootbot/php-tootbot) + - [php-tootbot/tootbot-template](https://github.com/php-tootbot/tootbot-template) +- [chillerlan/php-httpinterface](https://github.com/chillerlan/php-httpinterface) + - [chillerlan/php-http-message-utils](https://github.com/chillerlan/php-http-message-utils) + - [chillerlan/php-oauth-core](https://github.com/chillerlan/php-oauth-core) + - [chillerlan/php-oauth-providers](https://github.com/chillerlan/php-oauth-providers) +- [chillerlan/php-settings-container](https://github.com/chillerlan/php-settings-container) +- [chillerlan/php-dotenv](https://github.com/chillerlan/php-dotenv) + ## disclaimer WE'RE TOTALLY NOT RUNNING A PRODUCTION-LIKE ENVIRONMENT ON GITHUB.
diff --git a/cli/run.php b/cli/run.php index cc4bace1..842d1370 100644 --- a/cli/run.php +++ b/cli/run.php @@ -1,6 +1,6 @@ @@ -14,22 +14,15 @@ use Psr\Log\LogLevel; ini_set('date.timezone', 'UTC'); +#mb_internal_encoding('UTF-8'); require_once __DIR__.'/../vendor/autoload.php'; // if we're running on gh-actions, we're going to fetch the variables from gh.secrets, -if(isset($_SERVER['GITHUB_ACTIONS'])){ - $instance = getenv('MASTODON_INSTANCE'); - $apiToken = getenv('MASTODON_TOKEN'); +// otherwise we'll load them from the local .env file into the global environment +if(!isset($_SERVER['GITHUB_ACTIONS'])){ + (new DotEnv(__DIR__.'/../config', '.env', true))->load(); } -// otherwise we're loading them from the local .env file -else{ - $env = (new DotEnv(__DIR__.'/../config', '.env', false))->load(); - - $instance = $env->get('MASTODON_INSTANCE'); - $apiToken = $env->get('MASTODON_TOKEN'); -} - // invoke the options instance $options = new TootBotOptions; @@ -41,14 +34,14 @@ // OAuthOptionsTrait // these settings are only required for authentication/remote token acquisition -#$options->key = $env->get('MASTODON_KEY') ?? ''; -#$options->secret = $env->get('MASTODON_SECRET') ?? ''; -#$options->callbackURL = $env->get('MASTODON_CALLBACK_URL') ?? ''; +#$options->key = getenv('MASTODON_KEY'); +#$options->secret = getenv('MASTODON_SECRET'); +#$options->callbackURL = getenv('MASTODON_CALLBACK_URL'); #$options->sessionStart = true; // TootBotOptions -$options->instance = $instance; -$options->apiToken = $apiToken; +$options->instance = getenv('MASTODON_INSTANCE'); +$options->apiToken = getenv('MASTODON_TOKEN'); $options->loglevel = LogLevel::INFO; #$options->buildDir = __DIR__.'/../.build'; $options->dataDir = __DIR__.'/../data'; diff --git a/data/.gitkeep b/data/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/src/MyTootBot.php b/src/MyTootBot.php index 25813e69..7bc44201 100644 --- a/src/MyTootBot.php +++ b/src/MyTootBot.php @@ -2,23 +2,24 @@ /** * Class MyTootBot * + * @todo: update/change docblock + * * @created 03.02.2023 - * @author smiley - * @copyright 2023 smiley + * @author you + * @copyright 2023 you * @license MIT */ namespace PHPTootBot\MyTootBot; use PHPTootBot\PHPTootBot\TootBot; -use PHPTootBot\PHPTootBot\TootBotInterface; /** * */ class MyTootBot extends TootBot{ - public function post():TootBotInterface{ + public function post():static{ // TODO: Implement post() method. return $this; diff --git a/tests/MyTootBotTest.php b/tests/MyTootBotTest.php index c729ff87..26ee4761 100644 --- a/tests/MyTootBotTest.php +++ b/tests/MyTootBotTest.php @@ -2,9 +2,11 @@ /** * Class MyTootBotTest * + * @todo: update/change docblock + * * @created 03.02.2023 - * @author smiley - * @copyright 2023 smiley + * @author you + * @copyright 2023 you * @license MIT */