basyura's blog

あしたになったらほんきだす。

GitLab - コマンドラインから API を叩いてユーザを登録する

GitLab の API をコマンドラインで叩けるツール。

gitlab user create --email [email] --username [username] --name [name] --password [password] --confirm no
  • —confirm = no を指定すると認証をスキップする
  • update 時に指定すると変更されないっぽい (gitlab の引数リストには出てくるけど API ドキュメントには乗ってない)

Install

pip install python-gitlab

Config

~/.python-gitlab.cfg に設定を記述

[global]
default = somewhere
ssl_verify = true
timeout = 5

[somewhere]
url = https://some.whe.re
private_token = vTbFeqJYCY3sibBP7BZM

[elsewhere]
url = http://else.whe.re:8080
private_token = CkqsjqcQSFH5FQKDccu4
timeout = 1

User creation

Creates a new user. Note only administrators can create new users.

POST /users

Parameters:

  • email (required) - Email
  • password (required) - Password
  • username (required) - Username
  • name (required) - Name
  • skype (optional) - Skype ID
  • linkedin (optional) - LinkedIn
  • twitter (optional) - Twitter account
  • website_url (optional) - Website URL
  • projects_limit (optional) - Number of projects user can create
  • extern_uid (optional) - External UID
  • provider (optional) - External provider name
  • bio (optional) - User's biography
  • admin (optional) - User is admin - true or false (default)
  • can_create_group (optional) - User can create groups - true or false
  • confirm (optional) - Require confirmation - true (default) or false
User creation

User modification

Modifies an existing user. Only administrators can change attributes of a user.

PUT /users/:id

Parameters:

  • email - Email
  • username - Username
  • name - Name
  • password - Password
  • skype - Skype ID
  • linkedin - LinkedIn
  • twitter - Twitter account
  • website_url - Website URL
  • projects_limit - Limit projects each user can create
  • extern_uid - External UID
  • provider - External provider name
  • bio - User's biography
  • admin (optional) - User is admin - true or false (default)
  • can_create_group (optional) - User can create groups - true or false
User modification

GitLab - Custom Git Hooks

GitLab でサーバサイドフックを定義する方法。

Normally, git hooks are placed in the repository or project's hooks directory. GitLab creates a symlink from each project's hooks directory to the gitlab-shell hooks directory for ease of maintenance between gitlab-shell upgrades. As such, custom hooks are implemented a little differently. Behavior is exactly the same once the hook is created, though. Follow these steps to set up a custom hook.

  • Pick a project that needs a custom git hook.
  • On the GitLab server, navigate to the project's repository directory. For an installation from source the path is usually /home/git/repositories//.git. For Omnibus installs the path is usually /var/opt/gitlab/git-data/repositories//.git.
  • Create a new directory in this location called custom_hooks.
  • Inside the new custom_hooks directory, create a file with a name matching the hook type. For a pre-receive hook the file name should be pre-receive with no extension.
  • Make the hook file executable and make sure it's owned by git.
  • Write the code to make the git hook function as expected. Hooks can be in any language. Ensure the 'shebang' at the top properly reflects the language type. For example, if the script is in Ruby the shebang will probably be #!/usr/bin/env ruby.

That's it! Assuming the hook code is properly implemented the hook will fire as appropriate.

GitLab Documentation

概要

  • GitLab では .git/hooks フォルダ配下の各フックは全プロジェクト共通
  • プロジェクト個別にフックを定義したい場合は custom_hooks フォルダを作ってフックを格納するのが作法っぽい

構成

  • custom_hooks フォルダを作成しとその配下にフックを配置する
  • 各フックには適切な Permission を定義しておく
  • hooks はリンクが貼ってある

/var/opt/gitlab/git-data/repositories/SampleGroup/SampleProject.git プロジェクトの場合

SampleProject.git
├── FETCH_HEAD
├── HEAD
├── config
├── custom_hooks
│   ├── post-receive
│   ├── pre-receive
│   └── update
├── description
└── hooks -> /opt/gitlab/embedded/service/gitlab-shell/hooks
     ├── post-receive
     ├── pre-receive
     └── update

フックの呼び出し順

  • hooks/pre-receive
  • custom_hooks/pre-receive
  • hooks/update
  • custom_hooks/update
  • hooks/post-receive
  • custom_hooks/post-receive

共通サーバーサイドフックの中身

  • gitlab_custom_hook を読み込んで GitlabCustomHook を呼び出す
  • GitlabCustomHook から custom_hooks を呼び出す
#!/opt/gitlab/embedded/bin/ruby
# Fix the PATH so that gitlab-shell can find git-upload-pack and friends.
ENV['PATH'] = '/opt/gitlab/bin:/opt/gitlab/embedded/bin:' + ENV['PATH']

require_relative '../lib/gitlab_custom_hook'

if GitlabCustomHook.new.update(ref_name, old_value, new_value, repo_path)
  exit 0
else
  exit 1
end

#年間ブックマークランキング

2015年ブックマークランキングベスト8(累計13ブックマーク)

# タイトル
1位 yokohama.vim.osaka? #7 に行ってきた - basyura's blog
2位 Redmine - バージョンを見やすくする - basyura's blog
3位 Redmine - バージョンを見やすくする その2 - basyura's blog
4位 GitBucket - basyura's blog
5位 redmine - sidecontents plugin - basyura's blog
6位 プログラミング バカ一代 - basyura's blog
7位 Youtube 前後 - basyura's blog
8位 vimconf 2015 - basyura's blog


generated by 年間ブックマークランキングジェネレーター

しょぼかったwww

2015 年が終わるので El Capitan にアップデート

f:id:basyura:20151231164734p:plain:w200

ダウンロードに若干時間がかかったけどすんなりインストールが終わった。brew のために /usr/local を chown したくらいで他のアプリは特に問題なく動いてるようだ。

期待していたライブ変換はいい感じではあるのだけどデフォルトだと

  • キー入力が引っかかる感じが物凄くする
  • キーカスタマイズ等の設定変更がほとんどできない

というのが残念。これを使っておけという分にはいいのかもしれないけどちょっと違和感。キー入力の引っかかりは推測候補表示をオフにしたら若干改善した気がするけど、打鍵に遅れて変換されるのが目に見えちゃう時がよくある。キーカスタマイズはほとんどできないようなのだけど Karabiner でいじればとりあえずでできそう。

space 押下時に半角空白を入れる

<C-j> でエスケープする

Vim とか所々で使っているので追加。

<item>
  <name>ime cj escape</name>
  <identifier>private.ime_cj_escape</identifier>
  <inputsource_only>JA_IME</inputsource_only>
  <autogen>--KeyToKey-- KeyCode::J, ModifierFlag::CONTROL_L, KeyCode::ESCAPE</autogen>
</item>

<C-Return> 時にも確定する

ググる IME のリアルタイム変換の確定に使用していて誤爆するので追加。

<item>
  <name>ime c-enter enter</name>
  <identifier>private.ime_c-enter</identifier>
  <inputsource_only>JA_IME</inputsource_only>
  <autogen>
    __KeyToKey__
    KeyCode::RETURN, ModifierFlag::CONTROL_L,
    KeyCode::RETURN
  </autogen>
</item>

これで割といい感じになったのだけど、ググる IME を使う時には OFF にしないと挙動がおかしくなるので・・・それがネック。入力ソース決め打ちで指定できないんだろうか。どちらをメインに使っていくか悩む。

慣れかもしれないけどググる IME の方が軽いし (たぶん)、いろいろキーカスタマイズができて便利に思う。ライブ変換よりリアルタイム変換の方が賢い感じがするけどインラインで変換されるのはいいよなぁ。となると、差し引きで同点?ググる IME がインラインで予測変換してくれたら嬉しいのだけど最近アップデートがないしなぁ・・・。

フォント周りが変わったようなのだけど、Evernote で設定していた「ヒラギノ角ゴ ProN W3 14」が選択肢に出てこないのは仕方ないのだろうか。ヒラギノ角ゴは選べるのだけどもウエイトを色々変えてみてもイマイチ。Yosemite にあがった時だったかにも Evernote のフォントや行間が微妙に変わって違和感があったのがようやく落ち着いたと思ったのにまた同じようなことになるのか。Evernote はノートとしては単純でいいんだけど、固定フォントでコードを書く領域とか、左右に並べた段組でかけるとかいった機能が欲しいなぁ。ONE NOTE のようなフリーダムな感じはまったく要らないんだけどせめて行間設定できるオプションが欲しいよ。

今年もたくさんの人にお世話になった。

Bitnami (Redmine) 2.5 → 3.2 へアップデート

会社の Bitnami (Redmine) が 2.5 で古いのだけど Bitnami は一度アンインストールしてからインストールする必要があるようだったので放置してた。3.2 になるに至っていろいろ機能追加されてきた機能が欲しいというリクエストをもらったのでアップデート。vmware の windows で何回かアップデートの練習をしたおかげか特に問題なく終わった。後は、本体に直接入れていた修正をそのまま当て直すか、plugin 化するかが残っている状態。


以下アップデートのメモ

2.5 をアンインストール

念のためBitnami のルートフォルダからバックアップしておく。MySQL のデータはダンプしておく。
プログラムの追加と削除に登録されていないので (2.6 にはあった) インストールフォルダに有る uninstall.exe から実行

  • 「データも全て削除」を選択
  • レジストリキーを削除中を表示したまま応答なしの期間がけっこうあった。ディスクアクセス 100% だったのでノートンが過剰反応したように思う。
  • 4 つに増やしていた redmine のインスタンスも無事削除された
  • php の残骸が残っていたけど Bitnami フォルダごと削除

3.2 をインストール

アプリケーションの停止

  • manager-windows.exe を起動
  • MySQL 以外の各アプリケーションを停止する

ダンプファイルからリストア

コンソールを立ち上げる

  • use_redmine.bat を叩く
  • 必要な環境変数がセットされたコマンドプロンプトが起動する
  • rails、git、mysql 各コマンドが使えるようになる

MySQL にデータを読み込む

mysql -u bitnami -pパスワード bitnami_redmine < ファイルのパス

マイグレーション

> cd c:\Bitnami\redmine-3.2.0-0\apps\redmine\htdocs
> ruby -v
  ruby 2.0.0p647 (2015-08-18) [i386-mingw32]
> bundle exec rake db:migrate RAILS_ENV=production

email_addresses がすでに存在しているよエラーがでるけど、drop するとまずいので以下のファイルの中身をコメントアウトして再実行

  • 20150113194759_create_email_addresses.rb
  • 20150113213955_add_email_addresses_user_id_index.rb


その他の既にテーブルがある旨のエラーは中身が空であることを確認して drop する

mysql> drop table email_addresses;
mysql> drop table roles_managed_roles;
mysql> drop table imports;
mysql> drop table import_items;
mysql> drop table custom_field_enumerations;

再度マイグレーションを実行して終了を待つ。これ前にも遭遇した気がするのだけど、何か解決案はあるんだろうか?それともわざとそうなってるんだろうか?

plugin をインストール

  • plugins フォルダに git で clone
  • Redmine Q&A plugin が対応していなかったけど、とく使っていない上に手を入れてたりしてたので放置

入れている plugin 一覧

必要になって自作して入れてるもの

3.2 になって本体に取り込まれたので不要になったもの

plugin のアップデート

> bundle exec rake redmine:plugins:migrate RAILS_ENV=production

セションとキャッシュのクリア

bundle exec rake tmp:cache:clear tmp:sessions:clear

files フォルダを移す

  • バックアップから戻す
  • configuration.yaml の設定で files フォルダの位置を変更

メールの設定

  • configuration.yaml の設定

pdf 出力時のフォント設定

  • configuration.yaml の設定
rmagick_font_path: C:\windows\fonts\meiryo.ttc

ログ出力

config.logger = Logger.new("log/production.log", 5, 10 * 1024 * 1024)
config.log_level = :warn

2.5 では↓のようにログレベルを指定していたので、そのまま定義したのだけど効いてなかった。
logger の方の指定がちゃんと効いているかは不明・・・。

config.logger = Logger.new("log/production.log", 5, 10 * 1024 * 1024)
config.logger.level = Logger::WARN

アプリケーションの起動

  • manager-windows.exe を起動
  • アプリケーションを起動する

Redmine Comment Only plugin

テスト中にデフォルトの言語の中に日本語が出てこない現象が発生。ググってみると同じ現象が発生した人を発見。

http://ouranos.sakura.ne.jp/wordpress/2015/12/12/

自分の plugin が原因だった orz

原因を辿ってみると i18n.rb の中で言語を抽出してる時に蹴られちゃってるっぽいのだけどよく分からず。こういう時に型と IDE があれば・・・と思う・・。locale 周りっぽいことは分かったのでいろいろためしてみると、config/locales/en.yml の中に手抜きして en と ja の両方を定義していたのがダメだったようだ。

en:
  label_redmine_comment_only_display_all: 'display all history' 
ja:
  label_redmine_comment_only_display_all: '全ての履歴を表示' 

分割して問題解決。

まとめ

いろいろハマるんじゃないかなぁとか plugin がまた全部死んじゃうんだろうなぁとか思っていたのだけど、大きくハマることもなく済んでよかった。次にアップデートするのはまた一年後かな。